From 0cf92e82162051beffb11c230740f11bc02a104a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 4 Aug 2018 01:49:22 +0300 Subject: Add possible workaround for realpath overflow. --- src/fs/paths.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/fs/paths.cpp') diff --git a/src/fs/paths.cpp b/src/fs/paths.cpp index db9742daf..c13bdd966 100644 --- a/src/fs/paths.cpp +++ b/src/fs/paths.cpp @@ -38,17 +38,18 @@ #endif // USE_X11 #ifdef __native_client__ -#include #define realpath(N, R) strcpy(R, N) #endif // __native_client__ #ifdef WIN32 #include "fs/specialfolder.h" #define realpath(N, R) _fullpath((R), (N), _MAX_PATH) -#elif defined __OpenBSD__ +#endif + +#if defined __OpenBSD__ #include -#elif defined __native_client__ -#include +#else +#include #endif // WIN32 #ifndef WIN32 @@ -79,6 +80,12 @@ std::string getRealPath(const std::string &str) if (str.find("(unreachable)") != std::string::npos) return ""; #endif // defined(__GLIBC__) + + // possible fix for realpath overflow + if (str.size() > SSIZE_MAX / 10) + { + return std::string(); + } #if defined(__OpenBSD__) || defined(__ANDROID__) || defined(__native_client__) char *realPath = reinterpret_cast(calloc(PATH_MAX, sizeof(char))); if (!realPath) -- cgit v1.2.3-60-g2f50