From 28672dc2b4419582cd4a6dfc9b2dfd06f3f12c92 Mon Sep 17 00:00:00 2001 From: diaoliang Date: Mon, 19 Mar 2012 09:50:46 +0000 Subject: [PATCH] review url:http://rb.corp.taobao.com/r/25219/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit changelog: 1 merge了 liseen.wan@gmail.com提的patch. git-svn-id: http://code.taobao.org/svn/tengine/trunk@40 8a6cbc4f-5610-49f6-9325-3f9afe71ff98 --- THANKS.te | 1 + src/http/modules/ngx_http_limit_req_module.c | 29 +++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/THANKS.te b/THANKS.te index 0d1f4a1f..2ac638f7 100644 --- a/THANKS.te +++ b/THANKS.te @@ -1 +1,2 @@ perusio (Antnio P. P. Almeida) +liseen.wan diff --git a/src/http/modules/ngx_http_limit_req_module.c b/src/http/modules/ngx_http_limit_req_module.c index 9ca7b409..b1b57536 100644 --- a/src/http/modules/ngx_http_limit_req_module.c +++ b/src/http/modules/ngx_http_limit_req_module.c @@ -502,7 +502,8 @@ static ngx_int_t ngx_http_limit_req_lookup(ngx_http_request_t *r, ngx_http_limit_req_t *limit_req, ngx_uint_t hash, ngx_uint_t *ep) { - u_char *data, *last; + u_char *lr_data, *lr_last; + size_t lr_vv_len; ngx_int_t rc, excess; ngx_uint_t i; ngx_time_t *tp; @@ -538,25 +539,33 @@ ngx_http_limit_req_lookup(ngx_http_request_t *r, do { lr = (ngx_http_limit_req_node_t *) &node->color; - data = lr->data; - last = data + lr->len; + lr_data = lr->data; + lr_last = lr_data + lr->len; + for (i = 0; i < ctx->limit_vars->nelts; i++) { vv = ngx_http_get_indexed_variable(r, lrv[i].index); ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "limit_req vv is %i %v node is %s", - lrv[i].index, vv, data); - if ((rc = ngx_memn2cmp(data, vv->data, vv->len, vv->len)) != 0) - { + lrv[i].index, vv, lr_data); + + lr_vv_len = ngx_min(lr_last - lr_data, vv->len); + + if ((rc = ngx_memcmp(vv->data, lr_data, lr_vv_len)) != 0) { break; } - data += vv->len; - - if (data > last) { - rc = -1; + if (lr_vv_len != vv->len) { + rc = 1; break; } + + /* lr_vv_len == vv->len */ + lr_data += lr_vv_len; + } + + if (rc == 0 && lr_last > lr_data) { + rc = -1; } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,