]> git.kaiwu.me - nginx.git/commitdiff
Added checks that disallow adding a variable with an empty name.
authorRuslan Ermilov <ru@nginx.com>
Mon, 17 Dec 2012 19:03:33 +0000 (19:03 +0000)
committerRuslan Ermilov <ru@nginx.com>
Mon, 17 Dec 2012 19:03:33 +0000 (19:03 +0000)
Added variable name syntax checks to "geo" and "map" directives.

src/http/modules/ngx_http_geo_module.c
src/http/modules/ngx_http_limit_conn_module.c
src/http/modules/ngx_http_map_module.c
src/http/modules/ngx_http_rewrite_module.c
src/http/modules/ngx_http_split_clients_module.c
src/http/modules/perl/ngx_http_perl_module.c
src/http/ngx_http_variables.c

index 0e0aa0edcacf4388760368ca8c8033f96ad98414..1170cb337953546cb94a3180b5977fe3ccad48ab 100644 (file)
@@ -325,7 +325,7 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     name = value[1];
 
-    if (name.len < 2 || name.data[0] != '$') {
+    if (name.data[0] != '$') {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "invalid variable name \"%V\"", &name);
         return NGX_CONF_ERROR;
@@ -342,6 +342,13 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
         }
 
         name = value[2];
+
+        if (name.data[0] != '$') {
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                               "invalid variable name \"%V\"", &name);
+            return NGX_CONF_ERROR;
+        }
+
         name.len--;
         name.data++;
 
index 4f993557950093577bd3f343e822454f30faf718..e82ca493dab30ee967d5019e793db0444523f23b 100644 (file)
@@ -540,7 +540,7 @@ ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
             continue;
         }
 
-        if (value[i].len > 1 && value[i].data[0] == '$') {
+        if (value[i].data[0] == '$') {
 
             value[i].len--;
             value[i].data++;
@@ -613,7 +613,7 @@ ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     value = cf->args->elts;
 
-    if (value[2].len < 2 || value[2].data[0] != '$') {
+    if (value[2].data[0] != '$') {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "invalid variable name \"%V\"", &value[2]);
         return NGX_CONF_ERROR;
index 371737b2eac96ec3a8a7103047e1e558c73e14db..f5ee7673f16263bd1ff18f8beeb23b0ffcdde250 100644 (file)
@@ -209,6 +209,13 @@ ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
     }
 
     name = value[2];
+
+    if (name.data[0] != '$') {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           "invalid variable name \"%V\"", &name);
+        return NGX_CONF_ERROR;
+    }
+
     name.len--;
     name.data++;
 
index 9df090c77a4662ccce9c51561c5a0f71988c21d3..4081f87743343c775c9901e522d27553bd76a4cb 100644 (file)
@@ -908,7 +908,7 @@ ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     value = cf->args->elts;
 
-    if (value[1].len < 2 || value[1].data[0] != '$') {
+    if (value[1].data[0] != '$') {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "invalid variable name \"%V\"", &value[1]);
         return NGX_CONF_ERROR;
index 33a2fe73ee7350d592cca8477d6c87e6ef99978c..992f6de7c1bd10c69b234452386de39d4b2732ab 100644 (file)
@@ -139,7 +139,7 @@ ngx_conf_split_clients_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     name = value[2];
 
-    if (name.len < 2 || name.data[0] != '$') {
+    if (name.data[0] != '$') {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "invalid variable name \"%V\"", &name);
         return NGX_CONF_ERROR;
index 028b9f1999a69a3db5b15268eef37801b5233002..90e32e80efa5295bd4460292d82b564e9f399059 100644 (file)
@@ -968,7 +968,7 @@ ngx_http_perl_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     value = cf->args->elts;
 
-    if (value[1].len < 2 || value[1].data[0] != '$') {
+    if (value[1].data[0] != '$') {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "invalid variable name \"%V\"", &value[1]);
         return NGX_CONF_ERROR;
index db41964f5ef31a01620c09c509505a7a9f506017..d9f2e989490c378a9befca3af33070f2f518328f 100644 (file)
@@ -330,6 +330,12 @@ ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)
     ngx_http_variable_t        *v;
     ngx_http_core_main_conf_t  *cmcf;
 
+    if (name->len == 0) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           "invalid variable name \"$\"");
+        return NULL;
+    }
+
     cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 
     key = cmcf->variables_keys->keys.elts;
@@ -393,6 +399,12 @@ ngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name)
     ngx_http_variable_t        *v;
     ngx_http_core_main_conf_t  *cmcf;
 
+    if (name->len == 0) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           "invalid variable name \"$\"");
+        return NGX_ERROR;
+    }
+
     cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 
     v = cmcf->variables.elts;