From e049fd76f0d57c1e6400fbfbaf4cc6ebe540f16f Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Tue, 5 Jul 2022 23:41:38 +0000 Subject: Bugfix: Check for readlink buffer overflow and handle gracefully If readlink returns the size of the buffer, an overflow may have (safely) occurred. Pass a buffer size of MAX_PATH+1 (the size of the actual buffer) to detect this scenario. --- src/qt/guiutil.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 558d4f108c..cb8be5b9ba 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -743,9 +743,10 @@ bool SetStartOnSystemStartup(bool fAutoStart) else { char pszExePath[MAX_PATH+1]; - ssize_t r = readlink("/proc/self/exe", pszExePath, sizeof(pszExePath) - 1); - if (r == -1) + ssize_t r = readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)); + if (r == -1 || r > MAX_PATH) { return false; + } pszExePath[r] = '\0'; fs::create_directories(GetAutostartDir()); -- cgit v1.2.3