Skip to content

core: Distinguish invalid size parameters from range errors - #848

Closed
arturobernalg wants to merge 1 commit into
apache:trunkfrom
arturobernalg:fix/size-parameter-parse-einval
Closed

arturobernalg wants to merge 1 commit into
apache:trunkfrom
arturobernalg:fix/size-parameter-parse-einval

Conversation

@arturobernalg

@arturobernalg arturobernalg commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

ap_size_parameter_parse() (#829) returned APR_ERANGE for a value without any digits (abc, +, -) on libc implementations where strtoll() sets EINVAL when nothing is converted, such as FreeBSD and musl. glibc leaves errno alone there, so the function returned APR_EINVAL, as documented. The result depended on the libc.

When nothing is converted the C library stores the start of the string in the end pointer, so end == parameter tells portably that nothing was converted. Check it before the apr_strtoff() status. APR_EINVAL is for invalid syntax, APR_ERANGE stays for overflow and underflow.

LimitXMLRequestBody (#825) had its own apr_strtoff() parsing and had the same problem, so use the common function there as well. This is the change of #847. No change in the accepted values.

test_core_012_005 checks that LimitRequestBody reports invalid syntax and range errors with their own messages, and LimitXMLRequestBody is added to the directives of test_012. On glibc these tests pass with or without the change; they only catch the problem on FreeBSD and musl.

Tested with trunk at ba3fa29:

  • Linux (glibc): test/modules/core 279 passed; for 15 LimitRequestBody values the result is the same as before.
  • FreeBSD 14.5-RELEASE VM, test_010 and test_012: 7 failed and 228 passed on trunk, 235 passed with this change.
  • ap_size_parameter_parse() alone, with 14 inputs (valid, no digits, trailing characters, overflow, underflow): all correct on glibc and on musl (Alpine 3.17). On musl trunk gets 5 of them wrong.

No CHANGES entry: ap_size_parameter_parse() is trunk only and was never released, and the accepted values do not change.


  • This PR does not report or address a security vulnerability
    (see SECURITY.md and
    https://www.apache.org/security/#reporting-a-vulnerability).
  • Code follows the httpd style guide.
  • New log messages (level debug or higher) use an empty APLOGNO() tag;
    numbers are assigned by a committer at merge time (see docs/log-message-tags/README).
    (No new log messages.)
  • If the change is user-visible, a changes-entries/*.txt file is included,
    following the template in README.CHANGES (not needed otherwise).
    (Not needed, see above.)
  • Test cases based on pyhttpd are included where appropriate, in the
    test/modules/xxx directory matching the modules/xxx module source,
    or test/modules/core for core server changes. On Unix, verify these
    pass locally with e.g. make check-pytest PYTEST_DIRS=test/modules/xxx.

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.

@notroj notroj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

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