summaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-08-04 01:49:22 +0300
committerAndrei Karas <akaras@inbox.ru>2018-08-06 01:53:26 +0300
commit0cf92e82162051beffb11c230740f11bc02a104a (patch)
tree6f3c43cef265bda305e23390f48043d25d012f3a /src/fs
parent0db888042bdbc2c1abecd1e4328ccb8ee448bd0e (diff)
downloadmanaverse-0cf92e82162051beffb11c230740f11bc02a104a.tar.gz
manaverse-0cf92e82162051beffb11c230740f11bc02a104a.tar.bz2
manaverse-0cf92e82162051beffb11c230740f11bc02a104a.tar.xz
manaverse-0cf92e82162051beffb11c230740f11bc02a104a.zip
Add possible workaround for realpath overflow.
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/paths.cpp15
1 files changed, 11 insertions, 4 deletions
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 <limits.h>
#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 <limits>
-#elif defined __native_client__
-#include <limits.h>
+#else
+#include <climits>
#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<char*>(calloc(PATH_MAX, sizeof(char)));
if (!realPath)