From a06de1069009fb0f4c3b8ed298436503cfe2aa40 Mon Sep 17 00:00:00 2001 From: ZhaoPengyuan Date: Wed, 12 Aug 2020 11:43:52 +0800 Subject: [PATCH] fix codeDex warnings --- external/android-emugl/host/tools/emugen/TypeFactory.cpp | 7 +++++++ src/anbox/common/loop_device.cpp | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/external/android-emugl/host/tools/emugen/TypeFactory.cpp b/external/android-emugl/host/tools/emugen/TypeFactory.cpp index 1e0cc96e..b6c9dbe2 100644 --- a/external/android-emugl/host/tools/emugen/TypeFactory.cpp +++ b/external/android-emugl/host/tools/emugen/TypeFactory.cpp @@ -73,6 +73,7 @@ int TypeFactory::initFromFile(const std::string &filename) name = normalizeTypeDeclaration(name); if (name.size() == 0) { fprintf(stderr, "Error: %d : missing type name\n", lc); + fclose(fp); return -2; } pos = last + 1; @@ -80,6 +81,7 @@ int TypeFactory::initFromFile(const std::string &filename) size = getNextToken(str, pos, &last, WHITESPACE); if (size.size() == 0) { fprintf(stderr, "Error: %d : missing type width\n", lc); + fclose(fp); return -2; } pos = last + 1; @@ -87,6 +89,7 @@ int TypeFactory::initFromFile(const std::string &filename) printString = getNextToken(str, pos, &last, WHITESPACE); if (printString.size() == 0) { fprintf(stderr, "Error: %d : missing print-string\n", lc); + fclose(fp); return -2; } @@ -103,15 +106,18 @@ int TypeFactory::initFromFile(const std::string &filename) if (std::string("true")==pointerDef) { if (!isPointer) { fprintf(stderr, "Error: %d: invalid isPointer definition: 'true' but name does not end with '*'!\n", lc); + fclose(fp); return -2; } } else if (std::string("false")==pointerDef) { if (isPointer) { fprintf(stderr, "Error: %d: invalid isPointer definition: 'false' but name does end with '*'!\n", lc); + fclose(fp); return -2; } } else { fprintf(stderr, "Error: %d : invalid isPointer definition, must be either \"true\" or \"false\"\n", lc); + fclose(fp); return -2; } } @@ -139,6 +145,7 @@ int TypeFactory::initFromFile(const std::string &filename) isPointer))); //add a const type } g_initialized = true; + fclose(fp); return 0; } diff --git a/src/anbox/common/loop_device.cpp b/src/anbox/common/loop_device.cpp index f17222db..46aafbee 100644 --- a/src/anbox/common/loop_device.cpp +++ b/src/anbox/common/loop_device.cpp @@ -18,6 +18,7 @@ #include "anbox/common/loop_device.h" #include "anbox/defer_action.h" +#include #include #include @@ -50,7 +51,13 @@ bool LoopDevice::attach_file(const boost::filesystem::path &file_path) { if (fd_ < 0) return false; - int file_fd = ::open(file_path.c_str(), O_RDONLY); + const char* untrustPath = file_path.c_str(); + char path[PATH_MAX] = {0}; + if (realpath(untrustPath, path) == NULL) { + return false; + } + + int file_fd = ::open(path, O_RDONLY); if (file_fd < 0) return false; -- GitLab