Skip to content

Fix: Add errno check to strtol for detecting out-of-range width values#615

Open
ismaileneskucuk wants to merge 2 commits into
commonmark:masterfrom
ismaileneskucuk:fix-strtol-errno
Open

Fix: Add errno check to strtol for detecting out-of-range width values#615
ismaileneskucuk wants to merge 2 commits into
commonmark:masterfrom
ismaileneskucuk:fix-strtol-errno

Conversation

@ismaileneskucuk
Copy link
Copy Markdown
Contributor

Resolves #614
Added errno = 0 before parsing and an ERANGE check afterwards to safely exit with an error message when out-of-range width values are provided.

@nwellnhof
Copy link
Copy Markdown
Contributor

In addition, you have to check that the input string isn't empty, in which case unparsed[0] will be 0 despite no conversion being performed. Then we should reject negative or non-positive widths.

@ismaileneskucuk
Copy link
Copy Markdown
Contributor Author

Updated the logic to use unparsed == argv[i] to catch empty inputs.

Also added a check to reject < 0 values. 0 is kept valid since it is documented as the nowrap behavior.

Let me know if anything else is needed.

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.

Check errno after calling strtol

2 participants