From e885cc342a5396894cd49cb381e2b350517a450e Mon Sep 17 00:00:00 2001 From: kelson42 Date: Thu, 22 May 2014 19:05:42 +0200 Subject: [PATCH] + Avoid buffer overflow on linux --- src/common/pathTools.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/common/pathTools.cpp b/src/common/pathTools.cpp index ffd52b8b5..812246def 100644 --- a/src/common/pathTools.cpp +++ b/src/common/pathTools.cpp @@ -206,18 +206,22 @@ bool copyFile(const string &sourcePath, const string &destPath) { string getExecutablePath() { char binRootPath[PATH_MAX]; - + #ifdef _WIN32 GetModuleFileName( NULL, binRootPath, PATH_MAX); + return std::string(binRootPath); #elif __APPLE__ uint32_t max = (uint32_t)PATH_MAX; _NSGetExecutablePath(binRootPath, &max); + return std::string(binRootPath); #else - if (readlink("/proc/self/exe", binRootPath, PATH_MAX) == -1) { - }; + ssize_t size = readlink("/proc/self/exe", binRootPath, PATH_MAX); + if (size != -1) { + return std::string(binRootPath, size); + } #endif - return std::string(binRootPath); + return ""; } bool writeTextFile(const string &path, const string &content) {