Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changes-entries/limit-xml-request-body.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*) core: Reject invalid non-numeric values of LimitXMLRequestBody, as
LimitRequestBody does. PR 69975. [Arturo Bernal]
4 changes: 4 additions & 0 deletions changes-entries/size-parameter-parse.txt
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 2 additions & 1 deletion include/ap_mmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,14 +617,15 @@
* 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" */

#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
Expand Down
20 changes: 20 additions & 0 deletions include/httpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,26 @@ 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
* 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 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);

/**
* Determine if a request has a request body or not.
*
Expand Down
30 changes: 5 additions & 25 deletions modules/aaa/mod_auth_digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/aaa/mod_auth_form.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
Expand Down
8 changes: 4 additions & 4 deletions modules/cache/mod_cache_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand All @@ -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.";
Expand All @@ -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.";
Expand All @@ -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.";
Expand Down
10 changes: 5 additions & 5 deletions modules/cache/mod_cache_socache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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.";
}
Expand All @@ -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.";
}
Expand Down
4 changes: 2 additions & 2 deletions modules/filters/mod_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 3 additions & 26 deletions modules/filters/mod_substitute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
18 changes: 16 additions & 2 deletions modules/generators/mod_cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
18 changes: 16 additions & 2 deletions modules/generators/mod_cgid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
35 changes: 27 additions & 8 deletions server/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@

#include "mod_so.h" /* for ap_find_loaded_module_symbol */

#include <limits.h> /* for LONG_MAX */

#if defined(RLIMIT_CPU) || defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS) || defined (RLIMIT_NPROC)
#include "unixd.h"
#endif
Expand Down Expand Up @@ -3761,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;
}
Expand All @@ -3777,16 +3782,30 @@ 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;
apr_status_t rv;

conf->limit_xml_body = atol(arg);
if (conf->limit_xml_body < 0)
rv = ap_size_parameter_parse(arg, &limit);
if (rv == APR_ERANGE) {
return "LimitXMLRequestBody argument is not parsable.";
}
if (rv != APR_SUCCESS || 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;
}

Expand Down
Loading
Loading