From ba3ac9a0575c59e8c96a8f5ddd48d4debf0eb93d Mon Sep 17 00:00:00 2001 From: Tobias Frost Date: Sun, 17 Jan 2021 18:30:41 +0100 Subject: [PATCH] Avoid out-of-bound access on corner cases / when readlink fails. --- libs/module/ApplicationContextBase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/module/ApplicationContextBase.cpp b/libs/module/ApplicationContextBase.cpp index e3119f03cc..d900ec0518 100644 --- a/libs/module/ApplicationContextBase.cpp +++ b/libs/module/ApplicationContextBase.cpp @@ -187,7 +187,7 @@ const char* LINK_NAME = /// brief Returns the filename of the executable belonging to the current process, or 0 if not found. std::string getExecutablePath(char* argv[]) { - char buf[PATH_MAX]; + char buf[PATH_MAX+1]; // Now read the symbolic link int ret = readlink(LINK_NAME, buf, PATH_MAX); @@ -203,6 +203,7 @@ std::string getExecutablePath(char* argv[]) // In case of an error, leave the handling up to the caller return std::string(); } + ret = strlen(path); } /* Ensure proper NUL termination */