From 862562ce0db2b459a37460d3f263bfed7b9643b1 Mon Sep 17 00:00:00 2001 From: Matthias Maennich <matthias@maennich.net> Date: Thu, 5 Oct 2017 13:45:48 +0200 Subject: [PATCH] SystemInformation: fix potential off-by-one write in case readlink uses the complete buffer (1024) it will truncate the result and return 1024 assigned to ll. the subsequent buf[ll] will then be out of bounds. the fix assumes, that a truncated result is as useful as experiencing an error during readlink, hence falling back to /proc/self/exe. --- SystemInformation.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SystemInformation.cxx b/SystemInformation.cxx index 86fdccdc..366fe303 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -1346,7 +1346,7 @@ std::string SymbolProperties::GetBinary() const std::string binary; char buf[1024] = { '\0' }; ssize_t ll = 0; - if ((ll = readlink("/proc/self/exe", buf, 1024)) > 0) { + if ((ll = readlink("/proc/self/exe", buf, 1024)) > 0 && ll < 1024) { buf[ll] = '\0'; binary = buf; } else { -- GitLab