From f2afec473f3fad166f134fd32c88cab3fddc1d4e Mon Sep 17 00:00:00 2001 From: Thraix Date: Sun, 1 Mar 2020 21:01:27 +0100 Subject: [PATCH] Fix MakeGen crashing when entering invalid filepaths in dependency --- Makefile | 2 +- makegen.xml | 2 +- src/Common.h | 2 +- src/ConfigFile.cpp | 6 ++++-- src/FileUtils.h | 20 ++++++++++++++------ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index a1a1d21..ea1b320 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# This Makefile was generated using MakeGen v1.3.0 made by Tim HÃ¥kansson +# This Makefile was generated using MakeGen v1.3.2 made by Tim HÃ¥kansson # and is licensed under MIT. Full source of the project can be found at # https://github.com/Thraix/MakeGen CC=@g++ diff --git a/makegen.xml b/makegen.xml index 430f561..5ade169 100644 --- a/makegen.xml +++ b/makegen.xml @@ -19,5 +19,5 @@ src/ Release - v1.3.1 + v1.3.2 diff --git a/src/Common.h b/src/Common.h index 2a4b62b..ec38b5e 100755 --- a/src/Common.h +++ b/src/Common.h @@ -12,7 +12,7 @@ // Release, should be backwards compatible with any minor version #define MAKEGEN_VERSION_RELEASE 3 // Minor changes, generally bug fixes -#define MAKEGEN_VERSION_MINOR 1 +#define MAKEGEN_VERSION_MINOR 2 #define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR)) diff --git a/src/ConfigFile.cpp b/src/ConfigFile.cpp index 2b2ae32..7d503f0 100755 --- a/src/ConfigFile.cpp +++ b/src/ConfigFile.cpp @@ -333,6 +333,8 @@ std::optional ConfigFile::GetConfigFile(const std::string& filepath) std::optional ConfigFile::GetConfigFile(const std::string& filepath, std::map& loadedConfigs) { std::string realPath = FileUtils::GetRealPath(filepath); + if(realPath == "") + return {}; auto it = loadedConfigs.find(realPath); if(it != loadedConfigs.end()) { @@ -471,7 +473,7 @@ ConfigFile ConfigFile::Gen() configuration.AddXMLObject(XMLObject("srcdir", {}, srcdir)); configuration.AddXMLObject(XMLObject("outputdir", {}, outputdir)); configuration.AddXMLObject(XMLObject("hfilename", {}, hFile)); - configuration.AddXMLObject(XMLObject("outputtype", {}, + configuration.AddXMLObject(XMLObject("outputtype", {}, executable ? "executable" : (shared ? "sharedlibrary" : "staticlibrary"))); configuration.AddXMLObject(XMLObject("generatehfile", {}, generateHFile ? "true" : "false")); @@ -489,7 +491,7 @@ ConfigFile ConfigFile::Gen() configuration.AddXMLObject({"dependency",{},*it}); makegen.AddXMLObject(configuration); - return ConfigFile{makegen, FileUtils::GetRealPath("./")}; + return ConfigFile{makegen, FileUtils::GetRealPath(".")}; } void ConfigFile::Save() const diff --git a/src/FileUtils.h b/src/FileUtils.h index e5905d8..e58b33f 100644 --- a/src/FileUtils.h +++ b/src/FileUtils.h @@ -59,14 +59,22 @@ struct FileUtils static std::string GetRealPath(const std::string& filename) { #if defined(__linux__) - char* path = realpath(filename.c_str(), NULL); - std::string sPath = path; - sPath+="/"; - free(path); - return sPath; + if(access(filename.c_str(), F_OK ) != -1) + { + char* path = realpath(filename.c_str(), NULL); + std::string sPath = path; + sPath+="/"; + free(path); + return sPath; + } + else + { + LOG_ERROR("Directory doesn't exist: ", filename); + return ""; + } #endif LOG_ERROR("GetRealPath not supported"); - return filename; + return ""; } static std::string GetRelativePath(std::string from, std::string to)