Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid out-of-bound access on corner cases / when readlink fails. #14

Merged
merged 1 commit into from Jan 19, 2021
Merged

Avoid out-of-bound access on corner cases / when readlink fails. #14

merged 1 commit into from Jan 19, 2021

Conversation

coldtobi
Copy link

When looking if I could enable Hurd support (Hurd does not have PATH_MAX), I spotted these two out-of-bound bugs in getExecutablePath()

  1. if readlink fails, (returns -1), but the fallback worked, ret will still be -1, so the code will "Nul-Terminate" at buf[-1] (

  2. readlink might return PATH_MAX. In this case, the nul termination will write buf[PATH_MAX], one byte beyond the array.
    For this, it is easiest to just allocate 1 byte more for the array.

@codereader codereader merged commit a0300c9 into codereader:master Jan 19, 2021
@codereader
Copy link
Owner

Thanks a lot for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants