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.
This commit is contained in:
Matthew Kilgore 2017-07-26 08:29:56 -04:00
parent bafa0aa701
commit 7a073d3fc5

View File

@ -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;
}
}