From c376b705a5d2071a8ab10eee9d9267b7c8021888 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Wed, 14 Oct 2026 17:07:23 +0000 Subject: [PATCH 1/7] Merge r1939121 from trunk (test changes already on 2.4.x): 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 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939121 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit c1b7c82f7ed3de5ba2f52e43c0f59edb574ac5fd) --- changes-entries/limit-xml-request-body.txt | 2 ++ server/core.c | 25 +++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 changes-entries/limit-xml-request-body.txt diff --git a/changes-entries/limit-xml-request-body.txt b/changes-entries/limit-xml-request-body.txt new file mode 100644 index 00000000000..0d71cec7daf --- /dev/null +++ b/changes-entries/limit-xml-request-body.txt @@ -0,0 +1,2 @@ + *) core: Reject invalid non-numeric values of LimitXMLRequestBody, as + LimitRequestBody does. PR 69975. [Arturo Bernal] diff --git a/server/core.c b/server/core.c index df270b019e4..8de111f1533 100644 --- a/server/core.c +++ b/server/core.c @@ -58,6 +58,8 @@ #include "mod_so.h" /* for ap_find_loaded_module_symbol */ +#include /* for LONG_MAX */ + #if defined(RLIMIT_CPU) || defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS) || defined (RLIMIT_NPROC) #include "unixd.h" #endif @@ -3777,16 +3779,29 @@ static const char *set_limit_xml_req_body(cmd_parms *cmd, void *conf_, const char *arg) { core_dir_config *conf = conf_; + apr_uint64_t max = AP_MAX_LIMIT_XML_BODY; + apr_off_t limit; + char *errp; - conf->limit_xml_body = atol(arg); - if (conf->limit_xml_body < 0) + if (APR_SUCCESS != apr_strtoff(&limit, arg, &errp, 10)) { + return "LimitXMLRequestBody argument is not parsable."; + } + if (*errp || limit < 0) { return "LimitXMLRequestBody requires a non-negative integer."; + } - /* zero is AP_MAX_LIMIT_XML_BODY (implicitly) */ - if ((apr_size_t)conf->limit_xml_body > AP_MAX_LIMIT_XML_BODY) + /* zero is AP_MAX_LIMIT_XML_BODY (implicitly), and limit_xml_body is + * a long, which is narrower than apr_size_t on some platforms. + */ + if (max > LONG_MAX) { + max = LONG_MAX; + } + if ((apr_uint64_t)limit > max) { return apr_psprintf(cmd->pool, "LimitXMLRequestBody must not exceed " - "%" APR_SIZE_T_FMT, AP_MAX_LIMIT_XML_BODY); + "%" APR_UINT64_T_FMT, max); + } + conf->limit_xml_body = (long)limit; return NULL; } From c54801199f35edd3897e5d2a0e811c8c51a0cde9 Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Thu, 15 Oct 2026 03:41:47 +0000 Subject: [PATCH 2/7] Merge r1939129 from trunk (conflicts resolved in include/ap_mmn.h; DAVquota 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 #829 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939129 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit ba3fa296644994fc748b03cd8cb87bb282a6b5c6) --- changes-entries/size-parameter-parse.txt | 4 ++++ include/ap_mmn.h | 3 ++- include/httpd.h | 12 ++++++++++++ modules/aaa/mod_auth_form.c | 2 +- modules/cache/mod_cache_disk.c | 8 ++++---- modules/cache/mod_cache_socache.c | 10 +++++----- modules/filters/mod_buffer.c | 4 ++-- modules/generators/mod_cgi.c | 18 ++++++++++++++++-- modules/generators/mod_cgid.c | 18 ++++++++++++++++-- server/core.c | 9 ++++++--- server/util.c | 17 +++++++++++++++++ 11 files changed, 85 insertions(+), 20 deletions(-) create mode 100644 changes-entries/size-parameter-parse.txt diff --git a/changes-entries/size-parameter-parse.txt b/changes-entries/size-parameter-parse.txt new file mode 100644 index 00000000000..b8b128da654 --- /dev/null +++ b/changes-entries/size-parameter-parse.txt @@ -0,0 +1,4 @@ + *) core: Add ap_size_parameter_parse() and use it to reject malformed + ScriptLogLength, ScriptLogBuffer, BufferSize, AuthFormSize, and + mod_cache_disk and mod_cache_socache size and time values. + [Arturo Bernal] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 43bcaac0fb9..24d3d505a53 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -617,6 +617,7 @@ * options * 20120211.144 (2.4.72-dev) Add the optional function ap_authn_cache_store_env() * to mod_auth.h + * 20120211.145 (2.4.72-dev) Add ap_size_parameter_parse() to httpd.h */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ @@ -624,7 +625,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20120211 #endif -#define MODULE_MAGIC_NUMBER_MINOR 144 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 145 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/httpd.h b/include/httpd.h index eb24f820de0..b133adaf095 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -2231,6 +2231,18 @@ AP_DECLARE(apr_status_t) ap_timeout_parameter_parse( apr_interval_time_t *timeout, const char *default_time_unit); +/** + * Parse a configuration parameter as a base 10 apr_off_t. The whole parameter + * has to be a number, there must not be any other character after it. What + * values are acceptable is up to the caller. + * @param parameter The string containing the number. + * @param value The parsed value, only set on success. + * @return APR_SUCCESS, APR_EINVAL if the parameter is not a number, or + * APR_ERANGE if the number does not fit in an apr_off_t. + */ +AP_DECLARE(apr_status_t) ap_size_parameter_parse(const char *parameter, + apr_off_t *value); + /** * Determine if a request has a request body or not. * diff --git a/modules/aaa/mod_auth_form.c b/modules/aaa/mod_auth_form.c index d443092aa73..38f30d1a3b4 100644 --- a/modules/aaa/mod_auth_form.c +++ b/modules/aaa/mod_auth_form.c @@ -256,7 +256,7 @@ static const char *set_cookie_form_size(cmd_parms * cmd, void *config, auth_form_config_rec *conf = config; apr_off_t size; - if (APR_SUCCESS != apr_strtoff(&size, arg, NULL, 10) + if (APR_SUCCESS != ap_size_parameter_parse(arg, &size) || size < 0 || size > APR_SIZE_MAX) { return "AuthCookieFormSize must be a size in bytes, or zero."; } diff --git a/modules/cache/mod_cache_disk.c b/modules/cache/mod_cache_disk.c index 8d17a195f3c..27ce4c3f2d8 100644 --- a/modules/cache/mod_cache_disk.c +++ b/modules/cache/mod_cache_disk.c @@ -1481,7 +1481,7 @@ static const char { disk_cache_dir_conf *dconf = (disk_cache_dir_conf *)in_struct_ptr; - if (apr_strtoff(&dconf->minfs, arg, NULL, 10) != APR_SUCCESS || + if (ap_size_parameter_parse(arg, &dconf->minfs) != APR_SUCCESS || dconf->minfs < 0) { return "CacheMinFileSize argument must be a non-negative integer representing the min size of a file to cache in bytes."; @@ -1495,7 +1495,7 @@ static const char { disk_cache_dir_conf *dconf = (disk_cache_dir_conf *)in_struct_ptr; - if (apr_strtoff(&dconf->maxfs, arg, NULL, 10) != APR_SUCCESS || + if (ap_size_parameter_parse(arg, &dconf->maxfs) != APR_SUCCESS || dconf->maxfs < 0) { return "CacheMaxFileSize argument must be a non-negative integer representing the max size of a file to cache in bytes."; @@ -1509,7 +1509,7 @@ static const char { disk_cache_dir_conf *dconf = (disk_cache_dir_conf *)in_struct_ptr; - if (apr_strtoff(&dconf->readsize, arg, NULL, 10) != APR_SUCCESS || + if (ap_size_parameter_parse(arg, &dconf->readsize) != APR_SUCCESS || dconf->readsize < 0) { return "CacheReadSize argument must be a non-negative integer representing the max amount of data to cache in go."; @@ -1524,7 +1524,7 @@ static const char disk_cache_dir_conf *dconf = (disk_cache_dir_conf *)in_struct_ptr; apr_off_t milliseconds; - if (apr_strtoff(&milliseconds, arg, NULL, 10) != APR_SUCCESS || + if (ap_size_parameter_parse(arg, &milliseconds) != APR_SUCCESS || milliseconds < 0) { return "CacheReadTime argument must be a non-negative integer representing the max amount of time taken to cache in go."; diff --git a/modules/cache/mod_cache_socache.c b/modules/cache/mod_cache_socache.c index 38f1bfb2793..78bd3e7bb4c 100644 --- a/modules/cache/mod_cache_socache.c +++ b/modules/cache/mod_cache_socache.c @@ -1264,7 +1264,7 @@ static const char *set_cache_max(cmd_parms *parms, void *in_struct_ptr, { cache_socache_dir_conf *dconf = (cache_socache_dir_conf *) in_struct_ptr; - if (apr_strtoff(&dconf->max, arg, NULL, 10) != APR_SUCCESS + if (ap_size_parameter_parse(arg, &dconf->max) != APR_SUCCESS || dconf->max < 1024 || dconf->max > APR_UINT32_MAX) { return "CacheSocacheMaxSize argument must be a integer representing " "the max size of a cached entry (headers and body), at least 1024 " @@ -1280,7 +1280,7 @@ static const char *set_cache_maxtime(cmd_parms *parms, void *in_struct_ptr, cache_socache_dir_conf *dconf = (cache_socache_dir_conf *) in_struct_ptr; apr_off_t seconds; - if (apr_strtoff(&seconds, arg, NULL, 10) != APR_SUCCESS || seconds < 0) { + if (ap_size_parameter_parse(arg, &seconds) != APR_SUCCESS || seconds < 0) { return "CacheSocacheMaxTime argument must be the maximum amount of time in seconds to cache an entry."; } dconf->maxtime = apr_time_from_sec(seconds); @@ -1294,7 +1294,7 @@ static const char *set_cache_mintime(cmd_parms *parms, void *in_struct_ptr, cache_socache_dir_conf *dconf = (cache_socache_dir_conf *) in_struct_ptr; apr_off_t seconds; - if (apr_strtoff(&seconds, arg, NULL, 10) != APR_SUCCESS || seconds < 0) { + if (ap_size_parameter_parse(arg, &seconds) != APR_SUCCESS || seconds < 0) { return "CacheSocacheMinTime argument must be the minimum amount of time in seconds to cache an entry."; } dconf->mintime = apr_time_from_sec(seconds); @@ -1307,7 +1307,7 @@ static const char *set_cache_readsize(cmd_parms *parms, void *in_struct_ptr, { cache_socache_dir_conf *dconf = (cache_socache_dir_conf *) in_struct_ptr; - if (apr_strtoff(&dconf->readsize, arg, NULL, 10) != APR_SUCCESS + if (ap_size_parameter_parse(arg, &dconf->readsize) != APR_SUCCESS || dconf->readsize < 0) { return "CacheSocacheReadSize argument must be a non-negative integer representing the max amount of data to cache in go."; } @@ -1321,7 +1321,7 @@ static const char *set_cache_readtime(cmd_parms *parms, void *in_struct_ptr, cache_socache_dir_conf *dconf = (cache_socache_dir_conf *) in_struct_ptr; apr_off_t milliseconds; - if (apr_strtoff(&milliseconds, arg, NULL, 10) != APR_SUCCESS + if (ap_size_parameter_parse(arg, &milliseconds) != APR_SUCCESS || milliseconds < 0) { return "CacheSocacheReadTime argument must be a non-negative integer representing the max amount of time taken to cache in go."; } diff --git a/modules/filters/mod_buffer.c b/modules/filters/mod_buffer.c index 203e6724502..9f6519b0e33 100644 --- a/modules/filters/mod_buffer.c +++ b/modules/filters/mod_buffer.c @@ -321,8 +321,8 @@ static const char *set_buffer_size(cmd_parms *cmd, void *dconf, const char *arg) { buffer_conf *conf = dconf; - if (APR_SUCCESS != apr_strtoff(&(conf->size), arg, NULL, 10) || conf->size - <= 0) { + if (APR_SUCCESS != ap_size_parameter_parse(arg, &(conf->size)) + || conf->size <= 0) { return "BufferSize must be a size in bytes, and greater than zero"; } conf->size_set = 1; diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c index f0413ae9382..e81bb806b21 100644 --- a/modules/generators/mod_cgi.c +++ b/modules/generators/mod_cgi.c @@ -146,7 +146,14 @@ static const char *set_scriptlog_length(cmd_parms *cmd, void *dummy, cgi_server_conf *conf = ap_get_module_config(s->module_config, &cgi_module); - conf->logbytes = atol(arg); + apr_off_t bytes; + + if (ap_size_parameter_parse(arg, &bytes) != APR_SUCCESS + || bytes < 0 || bytes > LONG_MAX) { + return "ScriptLogLength must be a non-negative integer."; + } + + conf->logbytes = (long)bytes; return NULL; } @@ -157,7 +164,14 @@ static const char *set_scriptlog_buffer(cmd_parms *cmd, void *dummy, cgi_server_conf *conf = ap_get_module_config(s->module_config, &cgi_module); - conf->bufbytes = atoi(arg); + apr_off_t bytes; + + if (ap_size_parameter_parse(arg, &bytes) != APR_SUCCESS + || bytes < 0 || (apr_uint64_t)bytes > APR_SIZE_MAX) { + return "ScriptLogBuffer must be a non-negative integer."; + } + + conf->bufbytes = (apr_size_t)bytes; return NULL; } diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c index 0498658c065..2633eb9bcd2 100644 --- a/modules/generators/mod_cgid.c +++ b/modules/generators/mod_cgid.c @@ -1160,7 +1160,14 @@ static const char *set_scriptlog_length(cmd_parms *cmd, void *dummy, const char cgid_server_conf *conf = ap_get_module_config(s->module_config, &cgid_module); - conf->logbytes = atol(arg); + apr_off_t bytes; + + if (ap_size_parameter_parse(arg, &bytes) != APR_SUCCESS + || bytes < 0 || bytes > LONG_MAX) { + return "ScriptLogLength must be a non-negative integer."; + } + + conf->logbytes = (long)bytes; return NULL; } @@ -1170,7 +1177,14 @@ static const char *set_scriptlog_buffer(cmd_parms *cmd, void *dummy, const char cgid_server_conf *conf = ap_get_module_config(s->module_config, &cgid_module); - conf->bufbytes = atoi(arg); + apr_off_t bytes; + + if (ap_size_parameter_parse(arg, &bytes) != APR_SUCCESS + || bytes < 0 || bytes > INT_MAX) { + return "ScriptLogBuffer must be a non-negative integer."; + } + + conf->bufbytes = (int)bytes; return NULL; } diff --git a/server/core.c b/server/core.c index 8de111f1533..c64db9d1656 100644 --- a/server/core.c +++ b/server/core.c @@ -3763,14 +3763,17 @@ static const char *set_limit_req_body(cmd_parms *cmd, void *conf_, const char *arg) { core_dir_config *conf = conf_; - char *errp; + apr_off_t limit; + apr_status_t rv; - if (APR_SUCCESS != apr_strtoff(&conf->limit_req_body, arg, &errp, 10)) { + rv = ap_size_parameter_parse(arg, &limit); + if (rv == APR_ERANGE) { return "LimitRequestBody argument is not parsable."; } - if (*errp || conf->limit_req_body < 0) { + if (rv != APR_SUCCESS || limit < 0) { return "LimitRequestBody requires a non-negative integer."; } + conf->limit_req_body = limit; return NULL; } diff --git a/server/util.c b/server/util.c index 5eff6ba4209..6d52076462f 100644 --- a/server/util.c +++ b/server/util.c @@ -2681,6 +2681,23 @@ AP_DECLARE(apr_status_t) ap_timeout_parameter_parse( *timeout = (apr_interval_time_t)check; return APR_SUCCESS; } + +AP_DECLARE(apr_status_t) ap_size_parameter_parse(const char *parameter, + apr_off_t *value) +{ + apr_off_t parsed; + char *end; + + if (apr_strtoff(&parsed, parameter, &end, 10) != APR_SUCCESS) { + return APR_ERANGE; + } + if (end == parameter || *end != '\0') { + return APR_EINVAL; + } + + *value = parsed; + return APR_SUCCESS; +} #undef CHECK_OVERFLOW AP_DECLARE(int) ap_parse_strict_length(apr_off_t *len, const char *str) From 9b34ce6f76fd03b12a5141cfb6d1e9300977c39d Mon Sep 17 00:00:00 2001 From: Arturo Bernal Date: Fri, 16 Oct 2026 17:06:47 +0000 Subject: [PATCH 3/7] Merge r1939163 from trunk (test changes already on 2.4.x): 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 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939163 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit 93d7164cf48743d900cc89e3603cac6aee310e12) --- server/core.c | 7 ++++--- server/util.c | 11 +++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/core.c b/server/core.c index c64db9d1656..e608d769956 100644 --- a/server/core.c +++ b/server/core.c @@ -3784,12 +3784,13 @@ static const char *set_limit_xml_req_body(cmd_parms *cmd, void *conf_, 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."; } diff --git a/server/util.c b/server/util.c index 6d52076462f..2cc4195a1ed 100644 --- a/server/util.c +++ b/server/util.c @@ -2686,12 +2686,19 @@ AP_DECLARE(apr_status_t) ap_size_parameter_parse(const char *parameter, 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; } From e0448b1b2ad03cb3cc46ca4514be8a1ef545b61c Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Tue, 20 Oct 2026 19:29:29 +0000 Subject: [PATCH 4/7] Merge r1939295 from trunk (test changes already on 2.4.x): 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 GitHub: PR #851 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939295 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit 973155ccd4c9f145501388826cc3daec4a125f62) --- include/httpd.h | 11 +++++++---- server/util.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/include/httpd.h b/include/httpd.h index b133adaf095..281f30d5327 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -2232,13 +2232,16 @@ AP_DECLARE(apr_status_t) ap_timeout_parameter_parse( const char *default_time_unit); /** - * Parse a configuration parameter as a base 10 apr_off_t. The whole parameter - * has to be a number, there must not be any other character after it. What + * Parse a configuration parameter as a base 10 apr_off_t. The number may be + * followed by a single optional suffix, 'b'/'B' (bytes), 'k'/'K' (multiply + * by 1024), 'm'/'M' (multiply by 1024*1024) or 'g'/'G' (multiply by + * 1024*1024*1024); there must not be any other character after it. What * values are acceptable is up to the caller. * @param parameter The string containing the number. * @param value The parsed value, only set on success. - * @return APR_SUCCESS, APR_EINVAL if the parameter is not a number, or - * APR_ERANGE if the number does not fit in an apr_off_t. + * @return APR_SUCCESS, APR_EINVAL if the parameter is not a number with + * optional suffix, or APR_ERANGE if the value does not fit in an + * apr_off_t. */ AP_DECLARE(apr_status_t) ap_size_parameter_parse(const char *parameter, apr_off_t *value); diff --git a/server/util.c b/server/util.c index 2cc4195a1ed..304722b11ba 100644 --- a/server/util.c +++ b/server/util.c @@ -2685,7 +2685,10 @@ AP_DECLARE(apr_status_t) ap_timeout_parameter_parse( AP_DECLARE(apr_status_t) ap_size_parameter_parse(const char *parameter, apr_off_t *value) { - apr_off_t parsed; + /* The maximum apr_off_t value. */ + const apr_off_t off_max = sizeof(apr_off_t) == 8 ? APR_INT64_MAX + : APR_INT32_MAX; + apr_off_t parsed, multiplier = 1; apr_status_t rv; char *end; @@ -2698,11 +2701,32 @@ AP_DECLARE(apr_status_t) ap_size_parameter_parse(const char *parameter, if (rv != APR_SUCCESS) { return APR_ERANGE; } + + if (*end == 'k' || *end == 'K') { + multiplier = 1024; + end++; + } + else if (*end == 'm' || *end == 'M') { + multiplier = 1024 * 1024; + end++; + } + else if (*end == 'g' || *end == 'G') { + multiplier = 1024 * 1024 * 1024; + end++; + } + else if (*end == 'b' || *end == 'B') { + end++; + } if (*end != '\0') { return APR_EINVAL; } - *value = parsed; + if (parsed > off_max / multiplier + || parsed < (-off_max - 1) / multiplier) { + return APR_ERANGE; + } + + *value = parsed * multiplier; return APR_SUCCESS; } #undef CHECK_OVERFLOW From d1e16af5f582497b6179d57c6434b46b597f2ecd Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Tue, 20 Oct 2026 19:29:54 +0000 Subject: [PATCH 5/7] * 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 GitHub: closes #851 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1939296 13f79535-47bb-0310-9956-ffa450edef68 (cherry picked from commit aa1e6c0d497ca5b244dd4cf0c4366366b9e7e34d) --- modules/aaa/mod_auth_digest.c | 30 +++++------------------------- modules/filters/mod_substitute.c | 29 +++-------------------------- 2 files changed, 8 insertions(+), 51 deletions(-) diff --git a/modules/aaa/mod_auth_digest.c b/modules/aaa/mod_auth_digest.c index 39733e41084..1650d207c89 100644 --- a/modules/aaa/mod_auth_digest.c +++ b/modules/aaa/mod_auth_digest.c @@ -574,35 +574,15 @@ static const char *set_uri_list(cmd_parms *cmd, void *config, const char *uri) static const char *set_shmem_size(cmd_parms *cmd, void *config, const char *size_str) { - char *endptr; apr_off_t size; apr_size_t min; + apr_status_t rv; - if (apr_strtoff(&size, size_str, &endptr, 10) != APR_SUCCESS || size < 0) { - return apr_pstrcat(cmd->pool, "Invalid size in AuthDigestShmemSize: ", - size_str, NULL); - } - if (*endptr == 'k' || *endptr == 'K') { - if (size > APR_INT64_MAX / 1024) { - return "AuthDigestShmemSize value is too large"; - } - size *= 1024; - endptr++; - } - else if (*endptr == 'm' || *endptr == 'M') { - if (size > APR_INT64_MAX / (1024 * 1024)) { - return "AuthDigestShmemSize value is too large"; - } - size *= 1024 * 1024; - endptr++; - } - else if (*endptr == 'b' || *endptr == 'B') { - endptr++; - } - while (apr_isspace(*endptr)) { - endptr++; + rv = ap_size_parameter_parse(size_str, &size); + if (rv == APR_ERANGE) { + return "AuthDigestShmemSize value is too large"; } - if (*endptr != '\0') { + if (rv != APR_SUCCESS || size < 0) { return apr_pstrcat(cmd->pool, "Invalid size in AuthDigestShmemSize: ", size_str, NULL); } diff --git a/modules/filters/mod_substitute.c b/modules/filters/mod_substitute.c index fdb5b7dc1f0..86f6f8954ec 100644 --- a/modules/filters/mod_substitute.c +++ b/modules/filters/mod_substitute.c @@ -776,40 +776,17 @@ static const char *set_pattern(cmd_parms *cmd, void *cfg, const char *line) return NULL; } -#define KBYTE 1024 -#define MBYTE 1048576 -#define GBYTE 1073741824 static const char *set_max_line_length(cmd_parms *cmd, void *cfg, const char *arg) { subst_dir_conf *dcfg = (subst_dir_conf *)cfg; apr_off_t max; - char *end; apr_status_t rv; - rv = apr_strtoff(&max, arg, &end, 10); - if (rv == APR_SUCCESS) { - if ((*end == 'K' || *end == 'k') && !end[1]) { - if (max > APR_INT64_MAX / KBYTE) - return "SubstituteMaxLineLength value too large"; - max *= KBYTE; - } - else if ((*end == 'M' || *end == 'm') && !end[1]) { - if (max > APR_INT64_MAX / MBYTE) - return "SubstituteMaxLineLength value too large"; - max *= MBYTE; - } - else if ((*end == 'G' || *end == 'g') && !end[1]) { - if (max > APR_INT64_MAX / GBYTE) - return "SubstituteMaxLineLength value too large"; - max *= GBYTE; - } - else if (*end && /* neither empty nor [Bb] */ - ((*end != 'B' && *end != 'b') || end[1])) { - rv = APR_EGENERAL; - } + rv = ap_size_parameter_parse(arg, &max); + if (rv == APR_ERANGE) { + return "SubstituteMaxLineLength value too large"; } - if (rv != APR_SUCCESS || max < 0) { return "SubstituteMaxLineLength must be a non-negative integer optionally " From de16b7730672fe9da18a97891cc95a02c763eda5 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Sat, 28 Nov 2026 15:39:37 +0000 Subject: [PATCH 6/7] * test/modules/core/test_010_limit_xml_request_body.py (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 --- test/modules/core/test_010_limit_xml_request_body.py | 5 +++-- test/modules/core/test_012_config_off_t.py | 5 +++-- test/modules/filters/test_004_buffer_size.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/modules/core/test_010_limit_xml_request_body.py b/test/modules/core/test_010_limit_xml_request_body.py index 89052222df4..e9431d9739f 100644 --- a/test/modules/core/test_010_limit_xml_request_body.py +++ b/test/modules/core/test_010_limit_xml_request_body.py @@ -27,7 +27,8 @@ def test_core_010_001(self, env, value): # (without the change, only "-1" was rejected) @pytest.mark.parametrize("value", [ pytest.param(v, marks=not_backported( - "r1939121", "rejecting invalid LimitXMLRequestBody values")) + "r1939121", "rejecting invalid LimitXMLRequestBody values", + backported_in="2.4.72")) for v in ["abc123", "123abc", "123foo456", "1.5", "0x10", "+", "-"] ] + ["-1"]) def test_core_010_002(self, env, value): @@ -41,7 +42,7 @@ def test_core_010_002(self, env, value): ]) @not_backported("r1939121", "rejecting LimitXMLRequestBody values beyond a " "32-bit long, which atol() truncates on Windows", - platform="win32") + platform="win32", backported_in="2.4.72") def test_core_010_003(self, env, value): r = self.check_config(env, value) assert r.exit_code != 0, f"{value} was accepted" diff --git a/test/modules/core/test_012_config_off_t.py b/test/modules/core/test_012_config_off_t.py index 235487b2ae8..653f06674a0 100644 --- a/test/modules/core/test_012_config_off_t.py +++ b/test/modules/core/test_012_config_off_t.py @@ -15,9 +15,10 @@ "CacheSocacheReadTime", ] -OFF_T = not_backported("r1939129, r1939163", "strict size parsing for off_t directives") +OFF_T = not_backported("r1939129, r1939163", "strict size parsing for off_t directives", + backported_in="2.4.72") OFF_T_WIN = not_backported("r1939129, r1939163", "strict size parsing for off_t directives", - platform="win32") + platform="win32", backported_in="2.4.72") # Without the change (2.4.x), these directives take the number at the start of # a value and ignore the rest, and these also take a value without one; diff --git a/test/modules/filters/test_004_buffer_size.py b/test/modules/filters/test_004_buffer_size.py index d1b37b80d92..f0ef804f116 100644 --- a/test/modules/filters/test_004_buffer_size.py +++ b/test/modules/filters/test_004_buffer_size.py @@ -5,7 +5,7 @@ from pyhttpd.backport import not_backported from pyhttpd.conf import HttpdConf -STRICT = not_backported("r1939129", "strict BufferSize parsing") +STRICT = not_backported("r1939129", "strict BufferSize parsing", backported_in="2.4.72") class TestBufferSize: From 909f0244fcebeec59e151b4d4ab63a17dfede455 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Sat, 28 Nov 2026 15:54:53 +0000 Subject: [PATCH 7/7] * include/httpd.h (APR_ERANGE): Define for APR < 1.6. Co-Authored-By: Claude Fable 5.2 --- include/httpd.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/httpd.h b/include/httpd.h index 281f30d5327..759608075ac 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -2231,6 +2231,11 @@ AP_DECLARE(apr_status_t) ap_timeout_parameter_parse( apr_interval_time_t *timeout, const char *default_time_unit); +#ifndef APR_ERANGE +/* APR_ERANGE is not defined before APR 1.6. */ +#define APR_ERANGE ERANGE +#endif + /** * Parse a configuration parameter as a base 10 apr_off_t. The number may be * followed by a single optional suffix, 'b'/'B' (bytes), 'k'/'K' (multiply