Skip to content

common: set errno=0 before calling strto{l,ul,ull} #8412

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

whitslack
Copy link
Collaborator

The strto{l,ul,ull} functions do not set errno upon a successful return, so a successful return from a maximally valued input could be misinterpreted as an overflow error if errno happened already to be set to ERANGE before the call. To guard against this edge case, always set errno to zero before calling these functions if checking errno afterward.

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines. Trivial fix warrants no changelog message.
  • Tests have been added or modified to reflect the changes. Don't think it's worth writing tests for this edge case.
  • Documentation has been reviewed and updated as needed. There's no documentation to update.
  • Related issues have been listed and linked, including any that this PR closes. I doubt this has been reported, or else it would already have been fixed (I hope), but I didn't check.

The strto{l,ul,ull} functions do not set errno upon a successful return, so a
successful return from a maximally valued input could be misinterpreted as an
overflow error if errno happened already to be set to ERANGE before the call.
To guard against this edge case, always set errno to zero before calling these
functions if checking errno afterward.

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

Successfully merging this pull request may close these issues.

1 participant