aboutsummaryrefslogtreecommitdiff
path: root/src/http/ngx_http_variables.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2015-10-19 21:28:17 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2015-10-19 21:28:17 +0300
commitcc74c63d39fb644ae819f7ced19c03fa12cdec97 (patch)
tree5b34bfe777f80949e5e0d522d00b9b44e776d387 /src/http/ngx_http_variables.c
parentb9e0b9df446afa8a84d839bcf90b43d6504fc413 (diff)
downloadnginx-cc74c63d39fb644ae819f7ced19c03fa12cdec97.tar.gz
nginx-cc74c63d39fb644ae819f7ced19c03fa12cdec97.zip
Fixed variables prefix comparison.
Variable names are not null-terminated, so using ngx_strncmp() without extra length checks is wrong. Reported by Markus Linnala, http://mailman.nginx.org/pipermail/nginx-devel/2015-August/007211.html.
Diffstat (limited to 'src/http/ngx_http_variables.c')
-rw-r--r--src/http/ngx_http_variables.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index c65de358e..eaf294a12 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -575,7 +575,7 @@ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key)
return NULL;
}
- if (ngx_strncmp(name->data, "http_", 5) == 0) {
+ if (name->len >= 5 && ngx_strncmp(name->data, "http_", 5) == 0) {
if (ngx_http_variable_unknown_header_in(r, vv, (uintptr_t) name)
== NGX_OK)
@@ -586,7 +586,7 @@ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key)
return NULL;
}
- if (ngx_strncmp(name->data, "sent_http_", 10) == 0) {
+ if (name->len >= 10 && ngx_strncmp(name->data, "sent_http_", 10) == 0) {
if (ngx_http_variable_unknown_header_out(r, vv, (uintptr_t) name)
== NGX_OK)
@@ -597,7 +597,7 @@ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key)
return NULL;
}
- if (ngx_strncmp(name->data, "upstream_http_", 14) == 0) {
+ if (name->len >= 14 && ngx_strncmp(name->data, "upstream_http_", 14) == 0) {
if (ngx_http_upstream_header_variable(r, vv, (uintptr_t) name)
== NGX_OK)
@@ -608,7 +608,7 @@ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key)
return NULL;
}
- if (ngx_strncmp(name->data, "cookie_", 7) == 0) {
+ if (name->len >= 7 && ngx_strncmp(name->data, "cookie_", 7) == 0) {
if (ngx_http_variable_cookie(r, vv, (uintptr_t) name) == NGX_OK) {
return vv;
@@ -617,7 +617,9 @@ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key)
return NULL;
}
- if (ngx_strncmp(name->data, "upstream_cookie_", 16) == 0) {
+ if (name->len >= 16
+ && ngx_strncmp(name->data, "upstream_cookie_", 16) == 0)
+ {
if (ngx_http_upstream_cookie_variable(r, vv, (uintptr_t) name)
== NGX_OK)
@@ -628,7 +630,7 @@ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key)
return NULL;
}
- if (ngx_strncmp(name->data, "arg_", 4) == 0) {
+ if (name->len >= 4 && ngx_strncmp(name->data, "arg_", 4) == 0) {
if (ngx_http_variable_argument(r, vv, (uintptr_t) name) == NGX_OK) {
return vv;
@@ -2535,21 +2537,27 @@ ngx_http_variables_init_vars(ngx_conf_t *cf)
}
}
- if (ngx_strncmp(v[i].name.data, "http_", 5) == 0) {
+ if (v[i].name.len >= 5
+ && ngx_strncmp(v[i].name.data, "http_", 5) == 0)
+ {
v[i].get_handler = ngx_http_variable_unknown_header_in;
v[i].data = (uintptr_t) &v[i].name;
continue;
}
- if (ngx_strncmp(v[i].name.data, "sent_http_", 10) == 0) {
+ if (v[i].name.len >= 10
+ && ngx_strncmp(v[i].name.data, "sent_http_", 10) == 0)
+ {
v[i].get_handler = ngx_http_variable_unknown_header_out;
v[i].data = (uintptr_t) &v[i].name;
continue;
}
- if (ngx_strncmp(v[i].name.data, "upstream_http_", 14) == 0) {
+ if (v[i].name.len >= 14
+ && ngx_strncmp(v[i].name.data, "upstream_http_", 14) == 0)
+ {
v[i].get_handler = ngx_http_upstream_header_variable;
v[i].data = (uintptr_t) &v[i].name;
v[i].flags = NGX_HTTP_VAR_NOCACHEABLE;
@@ -2557,14 +2565,18 @@ ngx_http_variables_init_vars(ngx_conf_t *cf)
continue;
}
- if (ngx_strncmp(v[i].name.data, "cookie_", 7) == 0) {
+ if (v[i].name.len >= 7
+ && ngx_strncmp(v[i].name.data, "cookie_", 7) == 0)
+ {
v[i].get_handler = ngx_http_variable_cookie;
v[i].data = (uintptr_t) &v[i].name;
continue;
}
- if (ngx_strncmp(v[i].name.data, "upstream_cookie_", 16) == 0) {
+ if (v[i].name.len >= 16
+ && ngx_strncmp(v[i].name.data, "upstream_cookie_", 16) == 0)
+ {
v[i].get_handler = ngx_http_upstream_cookie_variable;
v[i].data = (uintptr_t) &v[i].name;
v[i].flags = NGX_HTTP_VAR_NOCACHEABLE;
@@ -2572,7 +2584,9 @@ ngx_http_variables_init_vars(ngx_conf_t *cf)
continue;
}
- if (ngx_strncmp(v[i].name.data, "arg_", 4) == 0) {
+ if (v[i].name.len >= 4
+ && ngx_strncmp(v[i].name.data, "arg_", 4) == 0)
+ {
v[i].get_handler = ngx_http_variable_argument;
v[i].data = (uintptr_t) &v[i].name;
v[i].flags = NGX_HTTP_VAR_NOCACHEABLE;