From 7a073d3fc5186fcab9d9502196a0da65b242a75b Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Wed, 26 Jul 2017 08:29:56 -0400 Subject: [PATCH] Fix GetApplicationDirectory() null termination error readlink is used to find the directory the executable resides in, however readlink does not null terminate the returned string. If the buffer does not have zero bytes at the end already, then you can have errors. --- src/core/support/Common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/support/Common.cpp b/src/core/support/Common.cpp index 7fb5d80b1..62b7ab603 100644 --- a/src/core/support/Common.cpp +++ b/src/core/support/Common.cpp @@ -76,7 +76,7 @@ std::string musik::core::GetApplicationDirectory() { result = result.substr(0, last); /* remove filename component */ #else std::string pathToProc = boost::str(boost::format("/proc/%d/exe") % (int) getpid()); - char pathbuf[PATH_MAX + 1]; + char pathbuf[PATH_MAX + 1] = { 0 }; readlink(pathToProc.c_str(), pathbuf, PATH_MAX); result.assign(pathbuf); size_t last = result.find_last_of("/"); @@ -266,4 +266,4 @@ close_and_return: } return success; -} \ No newline at end of file +}