Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #14 from coldtobi/fix_getExecutablePath
Avoid out-of-bound access on corner cases / when readlink fails.
  • Loading branch information
codereader committed Jan 19, 2021
2 parents 160302d + ba3ac9a commit a0300c9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libs/module/ApplicationContextBase.cpp
Expand Up @@ -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);
Expand All @@ -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 */
Expand Down

0 comments on commit a0300c9

Please sign in to comment.