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

prevent overflows in config_parseduration and config_parsebytesize #4536

Merged
merged 4 commits into from
Jul 4, 2023

Conversation

elliefm
Copy link
Contributor

@elliefm elliefm commented Jun 26, 2023

These two functions parse numbers from strings, and don't presently have any overflow protection. They're only used for parsing values from imapd.conf, so this hasn't been an issue -- the administrator can just choose not to use values that will break.

cyr_expire reads some of its behaviours from mailbox annotations, and #4533 extends it to support "duration" values for some of these annotations, using config_parseduration as its parser. I don't think I would expect users to have permissions to set these annotations, but if somehow they can, then config_parseduration might be processing user-supplied input, and ought to be protected against overflow just in case.

This PR adds overflow protection to config_parseduration, and also to config_parsebytesize for completion's sake. I also tightened up config_parseduration's parsing of bogus negative values.

@rsto previously made a version of this as #4534. I borrowed and extended his tests.

@elliefm elliefm force-pushed the v39/config_parsefoo-overflows branch 3 times, most recently from bb52d69 to f04809c Compare June 30, 2023 01:29
@elliefm elliefm force-pushed the v39/config_parsefoo-overflows branch 2 times, most recently from 632db36 to d45651f Compare June 30, 2023 03:07
@elliefm elliefm marked this pull request as ready for review June 30, 2023 03:08
@elliefm elliefm requested a review from rsto June 30, 2023 03:08
@elliefm
Copy link
Contributor Author

elliefm commented Jun 30, 2023

It turned out config_parsebytesize already used strtoll for the numeric part of the parsing, and it does so because bytesizes only permit a single numeric section with a single suffix anyway (like "1MB" but not "1MB23KB"). And use of strtoll meant it already had overflow detection for the numeric section, but it still needed overflow protection for the suffix multipliers, which I've added.

I've kept the config_parseduration implementation basically the same as it was, rather than converting it to use strtowhatever, because once you factor in the complexity of needing to parse multiple numeric sequences, the byte-by-byte parser is easier to read than a strtowhatever loop.

Copy link
Member

@rsto rsto left a comment

Choose a reason for hiding this comment

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

LGTM

@elliefm elliefm merged commit 212dc36 into cyrusimap:master Jul 4, 2023
@elliefm elliefm deleted the v39/config_parsefoo-overflows branch July 4, 2023 23:48
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.

2 participants