mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
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:
parent
bafa0aa701
commit
7a073d3fc5
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user