Merge bitcoin/bitcoin#26434: [24.x] [gui] Bugfix: Check for readlink buffer overflow and handle gracefully

e049fd76f0 Bugfix: Check for readlink buffer overflow and handle gracefully (Luke Dashjr)

Pull request description:

  Identical commit taken as-is from https://github.com/bitcoin/bitcoin/pull/25548 for backport

ACKs for top commit:
  hebasto:
    ACK e049fd76f0

Tree-SHA512: 37e63d570de898187c1bc8dd311c299c527adea51faa08aa6a3923bdb9390e3263902ace3d52a1cfc34ac2ba84e9358961574f886be1f64b5749a62e3c50ad57
This commit is contained in:
fanquake 2022-11-01 13:11:03 +00:00
commit 067dc42b79
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -615,9 +615,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());