summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2012-02-05 12:37:48 +0000
committerMaxim Dounin <mdounin@mdounin.ru>2012-02-05 12:37:48 +0000
commitc68a4cfdc54301d4ac7365d291dbe4af52b1294b (patch)
tree9930041bec8f451c56c9f3d41cba49cfdfca595d
parentb134a0cfa92d66c2c5a3f1e781aff524d14c3cb8 (diff)
downloadnginx-c68a4cfdc54301d4ac7365d291dbe4af52b1294b.tar.gz
Merge of r4335:
Fixed: some of $sent_http_* variables might contain header entries which actually wasn't sent to a client. The ngx_http_variable_headers() and ngx_http_variable_unknown_header() functions did not ignore response header entries with zero "hash" field. Thanks to Yichun Zhang (agentzh).
-rw-r--r--src/http/ngx_http_variables.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index 4afd88405..d2e43acef 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -640,8 +640,8 @@ static ngx_int_t
ngx_http_variable_headers(ngx_http_request_t *r, ngx_http_variable_value_t *v,
uintptr_t data)
{
- ssize_t len;
- u_char *p;
+ size_t len;
+ u_char *p, *end;
ngx_uint_t i, n;
ngx_array_t *a;
ngx_table_elt_t **h;
@@ -649,18 +649,30 @@ ngx_http_variable_headers(ngx_http_request_t *r, ngx_http_variable_value_t *v,
a = (ngx_array_t *) ((char *) r + data);
n = a->nelts;
+ h = a->elts;
- if (n == 0) {
+ len = 0;
+
+ for (i = 0; i < n; i++) {
+
+ if (h[i]->hash == 0) {
+ continue;
+ }
+
+ len += h[i]->value.len + sizeof("; ") - 1;
+ }
+
+ if (len == 0) {
v->not_found = 1;
return NGX_OK;
}
+ len -= sizeof("; ") - 1;
+
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
- h = a->elts;
-
if (n == 1) {
v->len = (*h)->value.len;
v->data = (*h)->value.data;
@@ -668,12 +680,6 @@ ngx_http_variable_headers(ngx_http_request_t *r, ngx_http_variable_value_t *v,
return NGX_OK;
}
- len = - (ssize_t) (sizeof("; ") - 1);
-
- for (i = 0; i < n; i++) {
- len += h[i]->value.len + sizeof("; ") - 1;
- }
-
p = ngx_pnalloc(r->pool, len);
if (p == NULL) {
return NGX_ERROR;
@@ -682,10 +688,17 @@ ngx_http_variable_headers(ngx_http_request_t *r, ngx_http_variable_value_t *v,
v->len = len;
v->data = p;
+ end = p + len;
+
for (i = 0; /* void */ ; i++) {
+
+ if (h[i]->hash == 0) {
+ continue;
+ }
+
p = ngx_copy(p, h[i]->value.data, h[i]->value.len);
- if (i == n - 1) {
+ if (p == end) {
break;
}
@@ -738,6 +751,10 @@ ngx_http_variable_unknown_header(ngx_http_variable_value_t *v, ngx_str_t *var,
i = 0;
}
+ if (header[i].hash == 0) {
+ continue;
+ }
+
for (n = 0; n + prefix < var->len && n < header[i].key.len; n++) {
ch = header[i].key.data[n];