From 5d82ce99434d6be2f720ee402401ff97edd85cf9 Mon Sep 17 00:00:00 2001 From: wankanzhen Date: Wed, 12 Aug 2020 20:23:58 +0800 Subject: [PATCH] fix simple bugs --- .../host/tools/emugen/ApiGen.cpp | 108 ++++++++++++++---- src/anbox/common/loop_device.cpp | 5 +- src/anbox/graphics/emugl/ColorBuffer.cpp | 9 ++ 3 files changed, 99 insertions(+), 23 deletions(-) diff --git a/external/android-emugl/host/tools/emugen/ApiGen.cpp b/external/android-emugl/host/tools/emugen/ApiGen.cpp index 142bf0e..2b65461 100644 --- a/external/android-emugl/host/tools/emugen/ApiGen.cpp +++ b/external/android-emugl/host/tools/emugen/ApiGen.cpp @@ -58,9 +58,15 @@ void ApiGen::printHeader(FILE *fp) const int ApiGen::genProcTypes(const std::string &filename, SideType side) { - FILE *fp = fopen(filename.c_str(), "wt"); + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *fp = fopen(path, "wt"); if (fp == NULL) { - perror(filename.c_str()); + perror(path); return -1; } printHeader(fp); @@ -102,9 +108,15 @@ int ApiGen::genProcTypes(const std::string &filename, SideType side) int ApiGen::genFuncTable(const std::string &filename, SideType side) { - FILE *fp = fopen(filename.c_str(), "wt"); + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *fp = fopen(path, "wt"); if (fp == NULL) { - perror(filename.c_str()); + perror(path); return -1; } printHeader(fp); @@ -133,9 +145,15 @@ int ApiGen::genFuncTable(const std::string &filename, SideType side) int ApiGen::genContext(const std::string & filename, SideType side) { - FILE *fp = fopen(filename.c_str(), "wt"); + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *fp = fopen(path, "wt"); if (fp == NULL) { - perror(filename.c_str()); + perror(path); return -1; } printHeader(fp); @@ -196,10 +214,15 @@ int ApiGen::genEntryPoints(const std::string & filename, SideType side) return -999; } + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } - FILE *fp = fopen(filename.c_str(), "wt"); + FILE *fp = fopen(path, "wt"); if (fp == NULL) { - perror(filename.c_str()); + perror(path); return errno; } @@ -268,9 +291,15 @@ int ApiGen::genEntryPoints(const std::string & filename, SideType side) int ApiGen::genOpcodes(const std::string &filename) { - FILE *fp = fopen(filename.c_str(), "wt"); + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *fp = fopen(path, "wt"); if (fp == NULL) { - perror(filename.c_str()); + perror(path); return errno; } @@ -313,9 +342,15 @@ int ApiGen::genAttributesTemplate(const std::string &filename ) int ApiGen::genEncoderHeader(const std::string &filename) { - FILE *fp = fopen(filename.c_str(), "wt"); + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *fp = fopen(path, "wt"); if (fp == NULL) { - perror(filename.c_str()); + perror(path); return -1; } @@ -753,9 +788,15 @@ int ApiGen::genEncoderImpl(const std::string &filename) int ApiGen::genDecoderHeader(const std::string &filename) { - FILE *fp = fopen(filename.c_str(), "wt"); + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *fp = fopen(path, "wt"); if (fp == NULL) { - perror(filename.c_str()); + perror(path); return -1; } @@ -801,9 +842,15 @@ int ApiGen::genDecoderHeader(const std::string &filename) int ApiGen::genContextImpl(const std::string &filename, SideType side) { - FILE *fp = fopen(filename.c_str(), "wt"); + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *fp = fopen(path, "wt"); if (fp == NULL) { - perror(filename.c_str()); + perror(path); return -1; } printHeader(fp); @@ -831,9 +878,15 @@ int ApiGen::genContextImpl(const std::string &filename, SideType side) int ApiGen::genDecoderImpl(const std::string &filename) { - FILE *fp = fopen(filename.c_str(), "wt"); + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *fp = fopen(path, "wt"); if (fp == NULL) { - perror(filename.c_str()); + perror(path); return -1; } @@ -1278,8 +1331,15 @@ int ApiGen::genDecoderImpl(const std::string &filename) int ApiGen::readSpec(const std::string & filename) { - FILE *specfp = fopen(filename.c_str(), "rt"); + const char* untrustPath = filename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *specfp = fopen(path, "rt"); if (specfp == NULL) { + perror(path); return -1; } @@ -1301,9 +1361,15 @@ int ApiGen::readAttributes(const std::string & attribFilename) { enum { ST_NAME, ST_ATT } state; - FILE *fp = fopen(attribFilename.c_str(), "rt"); + const char* untrustPath = attribFilename.c_str(); + char path[PATH_MAX] = {0}; + if(realpath(untrustPath, path) == NULL) { + return -1; + } + + FILE *fp = fopen(path, "rt"); if (fp == NULL) { - perror(attribFilename.c_str()); + perror(path); return -1; } char buf[1000]; diff --git a/src/anbox/common/loop_device.cpp b/src/anbox/common/loop_device.cpp index f17222d..88db115 100644 --- a/src/anbox/common/loop_device.cpp +++ b/src/anbox/common/loop_device.cpp @@ -28,11 +28,12 @@ namespace anbox { namespace common { std::shared_ptr LoopDevice::create(const boost::filesystem::path &path) { - const auto fd = ::open(path.c_str(), O_RDWR); + boost::filesystem::path abs_path = boost::filesystem::absolute(path); + const auto fd = ::open(abs_path.c_str(), O_RDWR); if (fd < 0) throw std::system_error{errno, std::system_category()}; - return std::shared_ptr(new LoopDevice(Fd{fd}, path)); + return std::shared_ptr(new LoopDevice(Fd{fd}, abs_path)); } LoopDevice::LoopDevice(Fd fd, const boost::filesystem::path &path) : diff --git a/src/anbox/graphics/emugl/ColorBuffer.cpp b/src/anbox/graphics/emugl/ColorBuffer.cpp index 51798c7..7d67ba3 100644 --- a/src/anbox/graphics/emugl/ColorBuffer.cpp +++ b/src/anbox/graphics/emugl/ColorBuffer.cpp @@ -128,6 +128,9 @@ ColorBuffer* ColorBuffer::create(EGLDisplay p_display, int p_width, } ColorBuffer* cb = new ColorBuffer(p_display, helper, hndl); + if (!cb) { + return NULL; + } s_gles2.glGenTextures(1, &cb->m_tex); s_gles2.glBindTexture(GL_TEXTURE_2D, cb->m_tex); @@ -172,6 +175,9 @@ ColorBuffer* ColorBuffer::create(EGLDisplay p_display, int p_width, } cb->m_resizer = new TextureResize(p_width, p_height); + if (!(cb->m_resizer)) { + return NULL; + } return cb; } @@ -322,6 +328,9 @@ bool ColorBuffer::bindToRenderbuffer() { return false; } RenderThreadInfo* tInfo = RenderThreadInfo::get(); + if (!tInfo) { + return false; + } if (!tInfo->currContext) { return false; } -- Gitee