Skip to content

[2.4.x] Merge ap_size_parameter_parse() - #1116

Merged
notroj merged 7 commits into
apache:2.4.xfrom
notroj:2.4.x-size-parameter-parse
Nov 28, 2026
Merged

notroj merged 7 commits into
apache:2.4.xfrom
notroj:2.4.x-size-parameter-parse

Conversation

@notroj

@notroj notroj commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Merge r1939121, r1939129, r1939163, r1939295, r1939296 from trunk:

core: Reject invalid values of LimitXMLRequestBody.

set_limit_xml_req_body() used atol(), so "abc123" and "123abc" were
accepted as 0 and 123, and a value out of range of a long gave an
undefined result. Parse the whole argument with apr_strtoff() like
LimitRequestBody, and reject values that do not fit in limit_xml_body
or exceed AP_MAX_LIMIT_XML_BODY.

PR: 69975
GitHub: closes #825

core: Add common apr_off_t config parser

Add ap_size_parameter_parse(), a helper to parse a configuration value
as an apr_off_t, which fails on trailing characters and on overflow.
The range of the value remains up to the directive.

Use it for configuration directives which parsed such values in
different ways, some of them accepting trailing characters or doing no
checks at all: LimitRequestBody (unchanged behavior), ScriptLogLength,
ScriptLogBuffer, DavQuota, BufferSize, AuthFormSize, and the
mod_cache_disk and mod_cache_socache size and time directives.

GitHub: closes #829

core: Distinguish invalid size parameters from range errors

ap_size_parameter_parse() returned APR_ERANGE for a value without any
digits where the libc sets EINVAL when nothing is converted (FreeBSD,
musl), and APR_EINVAL with glibc. end == parameter tells portably that
nothing was converted, so check it before the apr_strtoff() status.
APR_EINVAL is for invalid syntax, APR_ERANGE stays for overflow and
underflow.

Use it for LimitXMLRequestBody too, which had its own apr_strtoff()
parsing from #825, so that it reports the same errors as
LimitRequestBody on every platform. No change in the accepted values.

Extend test_012 to check that LimitRequestBody reports invalid syntax
and range errors with their own messages, and to cover
LimitXMLRequestBody.

GitHub: closes #848

core: Accept a b/k/m/g suffix in size-valued directive parameters:

  • server/util.c (ap_size_parameter_parse): Allow an optional
    case-insensitive 'b', 'k', 'm' or 'g' suffix, bounding the
    multiplication by the range of apr_off_t.

  • include/httpd.h: Update doxygen accordingly.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com
GitHub: PR #851

  • modules/aaa/mod_auth_digest.c (set_shmem_size),
    modules/filters/mod_substitute.c (set_max_line_length): Use
    ap_size_parameter_parse().

Co-Authored-By: Claude Fable 5 noreply@anthropic.com
GitHub: closes #851

r1939129 had a conflict in include/ap_mmn.h, resolved as a minor bump to 20120211.145. Its mod_dav_fs.c change is omitted because DAVquota is not in 2.4.x, and DavQuota is dropped from the changes entry to match. The test changes of all these revisions were already on 2.4.x.

APR_ERANGE only exists from APR 1.6, so include/httpd.h gains a fallback definition (ERANGE) for the APR 1.4 that 2.4.x still supports.

A further commit adds backported_in="2.4.72" to the not_backported marks for r1939121, r1939129 and r1939163; the same commit needs to land on trunk.

🤖 Generated with Claude Code

arturobernalg and others added 6 commits November 28, 2026 15:45
core: Reject invalid values of LimitXMLRequestBody.

set_limit_xml_req_body() used atol(), so "abc123" and "123abc" were
accepted as 0 and 123, and a value out of range of a long gave an
undefined result. Parse the whole argument with apr_strtoff() like
LimitRequestBody, and reject values that do not fit in limit_xml_body
or exceed AP_MAX_LIMIT_XML_BODY.

PR: 69975
GitHub: closes apache#825

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939121 13f79535-47bb-0310-9956-ffa450edef68
(cherry picked from commit c1b7c82)
…Vquota change omitted, not in 2.4.x; test changes already on 2.4.x):

core: Add common apr_off_t config parser

Add ap_size_parameter_parse(), a helper to parse a configuration value
as an apr_off_t, which fails on trailing characters and on overflow.
The range of the value remains up to the directive.

Use it for configuration directives which parsed such values in
different ways, some of them accepting trailing characters or doing no
checks at all: LimitRequestBody (unchanged behavior), ScriptLogLength,
ScriptLogBuffer, DavQuota, BufferSize, AuthFormSize, and the
mod_cache_disk and mod_cache_socache size and time directives.

GitHub: closes apache#829

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939129 13f79535-47bb-0310-9956-ffa450edef68
(cherry picked from commit ba3fa29)
core: Distinguish invalid size parameters from range errors

ap_size_parameter_parse() returned APR_ERANGE for a value without any
digits where the libc sets EINVAL when nothing is converted (FreeBSD,
musl), and APR_EINVAL with glibc. end == parameter tells portably that
nothing was converted, so check it before the apr_strtoff() status.
APR_EINVAL is for invalid syntax, APR_ERANGE stays for overflow and
underflow.

Use it for LimitXMLRequestBody too, which had its own apr_strtoff()
parsing from apache#825, so that it reports the same errors as
LimitRequestBody on every platform. No change in the accepted values.

Extend test_012 to check that LimitRequestBody reports invalid syntax
and range errors with their own messages, and to cover
LimitXMLRequestBody.

GitHub: closes apache#848

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939163 13f79535-47bb-0310-9956-ffa450edef68
(cherry picked from commit 93d7164)
core: Accept a b/k/m/g suffix in size-valued directive parameters:

* server/util.c (ap_size_parameter_parse): Allow an optional
  case-insensitive 'b', 'k', 'm' or 'g' suffix, bounding the
  multiplication by the range of apr_off_t.

* include/httpd.h: Update doxygen accordingly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
GitHub: PR apache#851

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939295 13f79535-47bb-0310-9956-ffa450edef68
(cherry picked from commit 973155c)
  modules/filters/mod_substitute.c (set_max_line_length): Use
  ap_size_parameter_parse().

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
GitHub: closes apache#851

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939296 13f79535-47bb-0310-9956-ffa450edef68
(cherry picked from commit aa1e6c0)
  (TestLimitXMLRequestBody.test_core_010_002,
  TestLimitXMLRequestBody.test_core_010_003),
  test/modules/core/test_012_config_off_t.py (OFF_T, OFF_T_WIN),
  test/modules/filters/test_004_buffer_size.py (STRICT): Mark as
  backported in 2.4.72.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@notroj
notroj force-pushed the 2.4.x-size-parameter-parse branch from 7cd8031 to de16b77 Compare November 28, 2026 15:46
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@notroj
notroj requested a review from arturobernalg November 28, 2026 18:27
@arturobernalg

Copy link
Copy Markdown
Member

Compared each commit with its trunk revision: identical apart from the MMN (.145 is right on top of #1097/#1111), the omitted DAVquota hunk and the changes entry. Builds clean here, also against APR 1.5.2 with the APR_ERANGE fallback (fails without it, as expected). The tests with backported_in="2.4.72" fail on unpatched 2.4.x and pass with the PR (366 passed). One thing worth a line in CHANGES and the docs, on trunk too: the suffix is user-visible. LimitRequestBody now accepts b/k/m/g, and "CacheMaxFileSize 10k" used to be read as 10 bytes and is now 10240; "10MB" and similar now fail at startup instead of being truncated.
+1 from me otherwise.

@arturobernalg arturobernalg left a comment •

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.

LGTM

@notroj

notroj commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @arturobernalg - will merge this as-is then amend docs/CHANGES separately.

@notroj
notroj merged commit b4336de into apache:2.4.x Nov 28, 2026
36 checks passed
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