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.
This commit is contained in:
Luke Dashjr 2022-07-05 23:41:38 +00:00
parent 9d9c4185fa
commit e049fd76f0

View file

@ -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());