Skip to content

tool_paramhlp: reject trailing garbage in seconds arguments - #23500

Closed
akashdeshmukh-git wants to merge 1 commit into
curl:masterfrom
akashdeshmukh-git:tool-secs2ms-trailing-garbage
Closed

akashdeshmukh-git wants to merge 1 commit into
curl:masterfrom
akashdeshmukh-git:tool-secs2ms-trailing-garbage

Conversation

@akashdeshmukh-git

@akashdeshmukh-git akashdeshmukh-git commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

secs2ms(), used for --connect-timeout, --expect100-timeout, --max-time, --retry-delay and --retry-max-time, did not check that the whole argument was consumed. Values like "10m" or "1.5abc" were silently accepted as 10 and 1.5 seconds, while str2num() and friends reject such input.

Also return PARAM_BAD_NUMERIC instead of PARAM_NUMBER_TOO_LARGE when no digits follow the decimal point, as in "1.".

Unit test tool1623 verifies.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The localized parsing changes match the intended behavior, include regression coverage, and have no identified blocking issues.

No open issues 🎉

What changed in this PR

Tightens seconds-argument parsing for curl command-line timeout and retry options.

Changes:

  • Rejects trailing garbage instead of silently accepting numeric prefixes.
  • Reports missing fractional digits as PARAM_BAD_NUMERIC.
  • Adds and registers regression test 3039.
File Description
tests/​data/​test3039 Checks rejection of --max-time 2m.
tests/​data/​Makefile.am Registers test 3039.
src/​tool_paramhlp.c Validates full argument consumption and distinguishes fractional parsing errors.

Review effort: Balanced

@testclutch

Copy link
Copy Markdown

Analysis of PR #23500 at 8f6b9c49:

Test ../../tests/http/test_02_download.py::TestDownload::test_02_34_max_total_conns[False-0-h2] failed, but it has been 0.6% flaky lately, so it's probably NOT a fault of the PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them).

Generated by Testclutch

@akashdeshmukh-git
akashdeshmukh-git force-pushed the tool-secs2ms-trailing-garbage branch from 8f6b9c4 to 518dec1 Compare October 21, 2026 07:02
Comment thread tests/data/test3039 Outdated
Pass in number with trailing garbage to --max-time
</name>
<command>
http://%HOSTIP:%NOLISTENPORT/%TESTNUMBER --max-time 2m

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need a separate test for this, and run it millions of times after this?
I'm not convinced. If important, try integrating into an existing where it fits.

@akashdeshmukh-git
akashdeshmukh-git force-pushed the tool-secs2ms-trailing-garbage branch from 518dec1 to c7c713a Compare October 22, 2026 06:13
@akashdeshmukh-git

Copy link
Copy Markdown
Contributor Author

Moved the checks into unit test 1623 instead of a new test.

@akashdeshmukh-git

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @vszakats.

That's a fair point — the unit tests for secs2ms() are already folded into the existing tests/tunit/tool1623.c (which already covers the size parser), so there is test coverage without test3039. I can drop test3039 entirely and rely solely on the unit tests in tool1623 if you prefer. Let me know and I'll update and mark this ready for review.

@akashdeshmukh-git

Copy link
Copy Markdown
Contributor Author

@vszakats The separate test is gone; the checks are now only in tool1623. Marking this ready for review.

@akashdeshmukh-git
akashdeshmukh-git marked this pull request as ready for review October 25, 2026 08:52
secs2ms(), used for --connect-timeout, --expect100-timeout, --max-time,
--retry-delay and --retry-max-time, did not check that the whole
argument was consumed. Values like "10m" or "1.5abc" were silently
accepted as 10 and 1.5 seconds, while str2num() and friends reject such
input.

Also return PARAM_BAD_NUMERIC instead of PARAM_NUMBER_TOO_LARGE when no
digits follow the decimal point, as in "1.".

Unit test 1623 now also checks secs2ms() with valid values and with
trailing garbage.
@akashdeshmukh-git
akashdeshmukh-git force-pushed the tool-secs2ms-trailing-garbage branch from 3f0472d to e53e767 Compare October 26, 2026 10:23
@bagder bagder closed this in 1422236 Oct 26, 2026
@bagder

bagder commented Oct 26, 2026

Copy link
Copy Markdown
Member

thanks!

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

Development

Successfully merging this pull request may close these issues.

5 participants