Skip to content

Commit

Permalink
Fix CID 1534125; String not null terminated in Path::getCurrentExecut…
Browse files Browse the repository at this point in the history
…ablePath()
  • Loading branch information
danmar committed Aug 18, 2024
1 parent 9aa63a7 commit cf91f51
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ std::string Path::getCurrentExecutablePath(const char* fallback)
#else // Linux
"/proc/self/exe";
#endif
success = (readlink(procPath, buf, sizeof(buf)) != -1);
// readlink does not null-terminate the string if the buffer is too small, therefore write bufsize - 1
success = (readlink(procPath, buf, sizeof(buf) - 1) != -1);
#endif
return success ? std::string(buf) : std::string(fallback);
}
Expand Down

0 comments on commit cf91f51

Please sign in to comment.