You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ab...@apache.org on 2026/10/16 17:06:48 UTC
svn commit: r1939163 - in httpd/httpd/trunk: server test/modules/core
Author: abernal
Date: Fri Oct 16 17:06:47 2026
New Revision: 1939163
Log:
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
Modified:
httpd/httpd/trunk/server/core.c
httpd/httpd/trunk/server/util.c
httpd/httpd/trunk/test/modules/core/test_012_config_off_t.py
Modified: httpd/httpd/trunk/server/core.c
==============================================================================
--- httpd/httpd/trunk/server/core.c Fri Oct 16 15:44:41 2026 (r1939162)
+++ httpd/httpd/trunk/server/core.c Fri Oct 16 17:06:47 2026 (r1939163)
@@ -3921,12 +3921,13 @@ static const char *set_limit_xml_req_bod
core_dir_config *conf = conf_;
apr_uint64_t max = AP_MAX_LIMIT_XML_BODY;
apr_off_t limit;
- char *errp;
+ apr_status_t rv;
- if (APR_SUCCESS != apr_strtoff(&limit, arg, &errp, 10)) {
+ rv = ap_size_parameter_parse(arg, &limit);
+ if (rv == APR_ERANGE) {
return "LimitXMLRequestBody argument is not parsable.";
}
- if (*errp || limit < 0) {
+ if (rv != APR_SUCCESS || limit < 0) {
return "LimitXMLRequestBody requires a non-negative integer.";
}
Modified: httpd/httpd/trunk/server/util.c
==============================================================================
--- httpd/httpd/trunk/server/util.c Fri Oct 16 15:44:41 2026 (r1939162)
+++ httpd/httpd/trunk/server/util.c Fri Oct 16 17:06:47 2026 (r1939163)
@@ -2778,12 +2778,19 @@ AP_DECLARE(apr_status_t) ap_size_paramet
apr_off_t *value)
{
apr_off_t parsed;
+ apr_status_t rv;
char *end;
- if (apr_strtoff(&parsed, parameter, &end, 10) != APR_SUCCESS) {
+ /* Check for no conversion before the status: some libc implementations
+ * set EINVAL when no digits are present. */
+ rv = apr_strtoff(&parsed, parameter, &end, 10);
+ if (end == parameter) {
+ return APR_EINVAL;
+ }
+ if (rv != APR_SUCCESS) {
return APR_ERANGE;
}
- if (end == parameter || *end != '\0') {
+ if (*end != '\0') {
return APR_EINVAL;
}
Modified: httpd/httpd/trunk/test/modules/core/test_012_config_off_t.py
==============================================================================
--- httpd/httpd/trunk/test/modules/core/test_012_config_off_t.py Fri Oct 16 15:44:41 2026 (r1939162)
+++ httpd/httpd/trunk/test/modules/core/test_012_config_off_t.py Fri Oct 16 17:06:47 2026 (r1939163)
@@ -7,7 +7,7 @@ from pyhttpd.conf import HttpdConf
# size and time directives parsed with ap_size_parameter_parse(), which can
# not be negative
DIRECTIVES = [
- "LimitRequestBody",
+ "LimitRequestBody", "LimitXMLRequestBody",
"ScriptLogLength", "ScriptLogBuffer",
"CacheMinFileSize", "CacheMaxFileSize", "CacheReadSize", "CacheReadTime",
"CacheSocacheMaxTime", "CacheSocacheMinTime", "CacheSocacheReadSize",
@@ -63,3 +63,24 @@ class TestConfigOffT:
else:
assert r.exit_code != 0, f"{value} was accepted"
assert "CacheSocacheMaxSize" in r.stderr, f"{r.stderr}"
+
+ # LimitRequestBody reports invalid syntax (APR_EINVAL) and a number
+ # which does not fit (APR_ERANGE) differently. A value without digits
+ # is invalid syntax regardless of the status returned by the
+ # underlying strto*() implementation: FreeBSD and musl set EINVAL
+ # there, glibc does not.
+ @pytest.mark.parametrize("value, error", [
+ ["abc", "requires a non-negative integer"],
+ ["+", "requires a non-negative integer"],
+ ["-", "requires a non-negative integer"],
+ ["abc123", "requires a non-negative integer"],
+ ["123abc", "requires a non-negative integer"],
+ ["12.3", "requires a non-negative integer"],
+ ["9223372036854775808", "argument is not parsable"],
+ ["-9223372036854775809", "argument is not parsable"],
+ ["9" * 40, "argument is not parsable"],
+ ])
+ def test_core_012_005(self, env, value, error):
+ r = self.check_config(env, "LimitRequestBody", value)
+ assert r.exit_code != 0, f"{value} was accepted"
+ assert f"LimitRequestBody {error}" in r.stderr, f"{r.stderr}"