summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2018-10-02 20:42:57 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2018-10-07 12:56:07 +0200
commit5393e7310d16656f2a84e0df589c54f9ccfbcd59 (patch)
treea6464b8c3f385756d85cdd102ec58a7e2940d53d
parent83acd5f17e67f6bbe586a061a4317815f176e196 (diff)
Avoid possible overflow in OS_Unix readlink
Also fix [-Wunused-result]
-rw-r--r--drivers/unix/os_unix.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 6c70934bc6..7ff27be501 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -487,9 +487,11 @@ String OS_Unix::get_executable_path() const {
//fix for running from a symlink
char buf[256];
memset(buf, 0, 256);
- readlink("/proc/self/exe", buf, sizeof(buf));
+ ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf));
String b;
- b.parse_utf8(buf);
+ if (len > 0) {
+ b.parse_utf8(buf, len);
+ }
if (b == "") {
WARN_PRINT("Couldn't get executable path from /proc/self/exe, using argv[0]");
return OS::get_executable_path();