diff --git a/external/android-emugl/host/tools/emugen/TypeFactory.cpp b/external/android-emugl/host/tools/emugen/TypeFactory.cpp index 1e0cc96e0517cdc3cbe61d9d75eee1e4be0b67d6..b6c9dbe21f904d7bf58b7dbf5ff3c440934aa17a 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 f17222db8f0088a97440866d9ad19b86f0044256..46aafbee48f0ba0267f6e8fd580135e2f4066e36 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;