Merge bitcoin/bitcoin#25548: gui: Check for readlink buffer overflow and handle gracefully

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

Pull request description:

  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.

ACKs for top commit:
  hebasto:
    ACK e049fd76f0.

Tree-SHA512: 188bace79cbe556efe7782e46b870c02729b07b104a9316b0f7d50013504972e85baf507403d2d6060bb2bf3e13f40d735bddd18255d97a60810208c3de87691
This commit is contained in:
fanquake 2022-11-01 11:05:40 +00:00
commit 5668ccec1d
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());