]> git.kaiwu.me - nginx.git/commitdiff
Rewrite: disallow empty replacements.
authorRuslan Ermilov <ru@nginx.com>
Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)
committerRuslan Ermilov <ru@nginx.com>
Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)
While empty replacements were caught at run-time, parsing code
of the "rewrite" directive expects that a minimum length of the
"replacement" argument is 1.

src/http/modules/ngx_http_rewrite_module.c

index 3b49c455cf3f9d0ff422c8d9a51c8451f140697d..0e6d4df64d09fea0dcaaff558a4e2e24ecffcf64 100644 (file)
@@ -318,6 +318,11 @@ ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     value = cf->args->elts;
 
+    if (value[2].len == 0) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "empty replacement");
+        return NGX_CONF_ERROR;
+    }
+
     ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
 
     rc.pattern = value[1];