]> granicus.if.org Git - apache/commitdiff
Fix error because of negative rate-limit
authorChristophe Jaillet <jailletc36@apache.org>
Mon, 28 Jan 2013 20:57:10 +0000 (20:57 +0000)
committerChristophe Jaillet <jailletc36@apache.org>
Mon, 28 Jan 2013 20:57:10 +0000 (20:57 +0000)
PR : 52964
Submitted by: Tianyin Xu <tixu cs ucsd edu>

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1439623 13f79535-47bb-0310-9956-ffa450edef68

modules/filters/mod_ratelimit.c

index 028de361ab317abd1e8f697c1f65a7874ac0316c..611017875e8732139c43fbb8d2f2f5c811ce536d 100644 (file)
@@ -74,6 +74,7 @@ rate_limit_filter(ap_filter_t *f, apr_bucket_brigade *input_bb)
     if (ctx == NULL) {
 
         const char *rl = NULL;
+        int ratelimit;
 
         /* no subrequests. */
         if (f->r->main != NULL) {
@@ -87,22 +88,21 @@ rate_limit_filter(ap_filter_t *f, apr_bucket_brigade *input_bb)
             ap_remove_output_filter(f);
             return ap_pass_brigade(f->next, bb);
         }
-
-        /* first run, init stuff */
-        ctx = apr_palloc(f->r->pool, sizeof(rl_ctx_t));
-        f->ctx = ctx;
-        ctx->speed = 0;
-        ctx->state = RATE_LIMIT;
-
+        
         /* rl is in kilo bytes / second  */
-        ctx->speed = atoi(rl) * 1024;
-
-        if (ctx->speed == 0) {
+        ratelimit = atoi(rl) * 1024;
+        if (ratelimit <= 0) {
             /* remove ourselves */
             ap_remove_output_filter(f);
             return ap_pass_brigade(f->next, bb);
         }
 
+        /* first run, init stuff */
+        ctx = apr_palloc(f->r->pool, sizeof(rl_ctx_t));
+        f->ctx = ctx;
+        ctx->state = RATE_LIMIT;
+        ctx->speed = ratelimit;
+
         /* calculate how many bytes / interval we want to send */
         /* speed is bytes / second, so, how many  (speed / 1000 % interval) */
         ctx->chunk_size = (ctx->speed / (1000 / RATE_INTERVAL_MS));