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

Fix error case memory bug in GetHostName() #11544

Closed
wants to merge 1 commit into from

Conversation

jowlyzhang
Copy link
Contributor

@jowlyzhang jowlyzhang commented Jun 15, 2023

Fix the error handling in GetHostName for non EFAULT, non EINVAL error. Current handling will cause stack overflow when non null-terminated c style string is in name, e.g. ENAMETOOLONG, when the name buffer is not big enough and the host name is truncated.

Test Plan:

COMPILE_WITH_ASAN=1 make all check

@facebook-github-bot
Copy link
Contributor

@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@jowlyzhang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! I suggest a more clear and direct summary like "Fix error case memory bug in GetHostName()". In case you were taking inspiration from some of the soft language in my PR #11538, that is kind of a special case where it's hard to promise what is actually safe usage during static destruction and we nevertheless need to make reasonable accommodations to avoid bugs or crashes, as there might not be a clear path to guaranteed safe usage.

In this case, the old code was completely unsafe (on an error handling path).

Rant: It would be nice to deprecate and get rid of this API with its C-style calling conventions, but that's probably more work than it's worth. Back to the important things.

@jowlyzhang jowlyzhang changed the title Make the error message safer Fix error case memory bug in GetHostName() Jun 16, 2023
@jowlyzhang
Copy link
Contributor Author

Thanks for the fix! I suggest a more clear and direct summary like "Fix error case memory bug in GetHostName()". In case you were taking inspiration from some of the soft language in my PR #11538, that is kind of a special case where it's hard to promise what is actually safe usage during static destruction and we nevertheless need to make reasonable accommodations to avoid bugs or crashes, as there might not be a clear path to guaranteed safe usage.

In this case, the old code was completely unsafe (on an error handling path).

Rant: It would be nice to deprecate and get rid of this API with its C-style calling conventions, but that's probably more work than it's worth. Back to the important things.

Thanks Peter for the review and the suggested summary. You are right that this is not just a good-to-have improvement, but an absolutely necessary fix for an incorrectly handled error case.

@facebook-github-bot
Copy link
Contributor

@jowlyzhang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@jowlyzhang merged this pull request in 6649978.

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

Successfully merging this pull request may close these issues.

3 participants