Skip to content

Commit fe1ee0a

Browse files
committed
add MaxRanges directive institute a default limit of 200 (post-merge where
applicable) Ranges before returning the complete resource. (minor mmn bump for core_dir_config addition) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1162584 13f79535-47bb-0310-9956-ffa450edef68
1 parent b14e8a7 commit fe1ee0a

5 files changed

Lines changed: 40 additions & 2 deletions

File tree

CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-*- coding: utf-8 -*-
22
Changes with Apache 2.3.15
33

4+
*) core: Add MaxRanges directive to control the number of ranges permitted
5+
before returning the entire resource, with a default limit of 200.
6+
[Eric Covener]
7+
48
*) mod_cache: Ensure that CacheDisable can correctly appear within
59
a LocationMatch. [Graham Leggett]
610

include/ap_mmn.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,15 @@
348348
* 20110724.1 (2.3.15-dev) add NOT_IN_HTACCESS
349349
* 20110724.2 (2.3.15-dev) retries and retry_delay in util_ldap_state_t
350350
* 20110724.3 (2.3.15-dev) add util_varbuf.h / ap_varbuf API
351+
* 20110724.4 (2.3.15-dev) add max_ranges to core_dir_config
351352
*/
352353

353354
#define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
354355

355356
#ifndef MODULE_MAGIC_NUMBER_MAJOR
356357
#define MODULE_MAGIC_NUMBER_MAJOR 20110724
357358
#endif
358-
#define MODULE_MAGIC_NUMBER_MINOR 3 /* 0...n */
359+
#define MODULE_MAGIC_NUMBER_MINOR 4 /* 0...n */
359360

360361
/**
361362
* Determine if the server's current MODULE_MAGIC_NUMBER is at least a

include/http_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ typedef struct {
605605
/** Table of directives allowed per AllowOverrideList */
606606
apr_table_t *override_list;
607607

608+
/** Number of Ranges before returning HTTP_OK, 0/unlimited -1/unset. **/
609+
int max_ranges;
610+
608611
} core_dir_config;
609612

610613
/* macro to implement off by default behaviour */

modules/http/byterange_filter.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
#include <unistd.h>
6060
#endif
6161

62+
#ifndef DEFAULT_MAX_RANGES
63+
#define DEFAULT_MAX_RANGES 200
64+
#endif
65+
6266
APLOG_USE_MODULE(http);
6367

6468
static int ap_set_byterange(request_rec *r, apr_off_t clength,
@@ -255,6 +259,11 @@ typedef struct indexes_t {
255259
apr_off_t end;
256260
} indexes_t;
257261

262+
static int get_max_ranges(request_rec *r) {
263+
core_dir_config *core_conf = ap_get_core_module_config(r->per_dir_config);
264+
return core_conf->max_ranges == -1 ? DEFAULT_MAX_RANGES : core_conf->max_ranges;
265+
}
266+
258267
AP_CORE_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f,
259268
apr_bucket_brigade *bb)
260269
{
@@ -274,6 +283,8 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f,
274283
apr_array_header_t *indexes;
275284
indexes_t *idx;
276285
int i;
286+
int original_status;
287+
int max_ranges = get_max_ranges(r);
277288

278289
/*
279290
* Iterate through the brigade until reaching EOS or a bucket with
@@ -297,10 +308,12 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f,
297308
return ap_pass_brigade(f->next, bb);
298309
}
299310

311+
original_status = r->status;
300312
num_ranges = ap_set_byterange(r, clength, &indexes);
301313

302314
/* We have nothing to do, get out of the way. */
303-
if (num_ranges == 0) {
315+
if (num_ranges == 0 || (max_ranges > 0 && num_ranges > max_ranges)) {
316+
r->status = original_status;
304317
ap_remove_output_filter(f);
305318
return ap_pass_brigade(f->next, bb);
306319
}

server/core.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ static void *create_core_dir_config(apr_pool_t *a, char *dir)
178178
conf->enable_sendfile = ENABLE_SENDFILE_UNSET;
179179
conf->allow_encoded_slashes = 0;
180180
conf->decode_encoded_slashes = 0;
181+
182+
conf->max_ranges = -1;
181183

182184
return (void *)conf;
183185
}
@@ -397,6 +399,8 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
397399
}
398400
}
399401

402+
conf->max_ranges = new->max_ranges != -1 ? new->max_ranges : base->max_ranges;
403+
400404
return (void*)conf;
401405
}
402406

@@ -3260,6 +3264,16 @@ static const char *set_limit_xml_req_body(cmd_parms *cmd, void *conf_,
32603264
return NULL;
32613265
}
32623266

3267+
static const char *set_max_ranges(cmd_parms *cmd, void *conf_, const char *arg)
3268+
{
3269+
core_dir_config *conf = conf_;
3270+
3271+
conf->max_ranges = atoi(arg);
3272+
if (conf->max_ranges < 0)
3273+
return "MaxRanges requires a non-negative integer (0 = unlimited)";
3274+
3275+
return NULL;
3276+
}
32633277
AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r)
32643278
{
32653279
core_dir_config *conf;
@@ -3876,6 +3890,9 @@ AP_INIT_TAKE1("LimitXMLRequestBody", set_limit_xml_req_body, NULL, OR_ALL,
38763890
AP_INIT_RAW_ARGS("Mutex", ap_set_mutex, NULL, RSRC_CONF,
38773891
"mutex (or \"default\") and mechanism"),
38783892

3893+
AP_INIT_TAKE1("MaxRanges", set_max_ranges, NULL, RSRC_CONF|ACCESS_CONF,
3894+
"Maximum number of Ranges in a request before returning the entire "
3895+
"resource, or 0 for unlimited"),
38793896
/* System Resource Controls */
38803897
#ifdef RLIMIT_CPU
38813898
AP_INIT_TAKE12("RLimitCPU", set_limit_cpu,

0 commit comments

Comments
 (0)