]> git.kaiwu.me - nginx.git/commitdiff
Perl: expect escaped URIs in $r->internal_redirect().
authorMaxim Dounin <mdounin@mdounin.ru>
Fri, 12 Jul 2019 12:39:26 +0000 (15:39 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Fri, 12 Jul 2019 12:39:26 +0000 (15:39 +0300)
Similarly to the change in 5491:74bfa803a5aa (1.5.9), we should accept
properly escaped URIs and unescape them as needed, else it is not possible
to handle URIs with question marks.

src/http/modules/perl/nginx.xs
src/http/modules/perl/ngx_http_perl_module.c
src/http/modules/perl/ngx_http_perl_module.h

index 7370bf5fcd1f10ad6fb7f302ef7e7d0742349a5a..309b7cbfb01e36ba4c79512cb5e211ef7c206fe7 100644 (file)
@@ -952,17 +952,6 @@ internal_redirect(r, uri)
         croak("ngx_http_perl_sv2str() failed");
     }
 
-    for (i = 0; i < ctx->redirect_uri.len; i++) {
-        if (ctx->redirect_uri.data[i] == '?') {
-
-            ctx->redirect_args.len = ctx->redirect_uri.len - (i + 1);
-            ctx->redirect_args.data = &ctx->redirect_uri.data[i + 1];
-            ctx->redirect_uri.len = i;
-
-            XSRETURN_EMPTY;
-        }
-    }
-
 
 void
 allow_ranges(r)
index d2a0dfae546e62020ab2cc378bbcbc033e606df9..a123e3875bacbb30bfcdcbab93a34eac5a631b74 100644 (file)
@@ -184,6 +184,7 @@ ngx_http_perl_handle_request(ngx_http_request_t *r)
     SV                         *sub;
     ngx_int_t                   rc;
     ngx_str_t                   uri, args, *handler;
+    ngx_uint_t                  flags;
     ngx_http_perl_ctx_t        *ctx;
     ngx_http_perl_loc_conf_t   *plcf;
     ngx_http_perl_main_conf_t  *pmcf;
@@ -237,7 +238,6 @@ ngx_http_perl_handle_request(ngx_http_request_t *r)
 
     if (ctx->redirect_uri.len) {
         uri = ctx->redirect_uri;
-        args = ctx->redirect_args;
 
     } else {
         uri.len = 0;
@@ -257,6 +257,14 @@ ngx_http_perl_handle_request(ngx_http_request_t *r)
     }
 
     if (uri.len) {
+        ngx_str_null(&args);
+        flags = NGX_HTTP_LOG_UNSAFE;
+
+        if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) {
+            ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+            return;
+        }
+
         ngx_http_internal_redirect(r, &uri, &args);
         ngx_http_finalize_request(r, NGX_DONE);
         return;
index da3a162353eaac25711e5e6141444389c0878799..8fa59a4c5dac0607159deacee18c6c0d0c7ca6c6 100644 (file)
@@ -25,7 +25,6 @@ typedef struct {
 
     ngx_str_t                 filename;
     ngx_str_t                 redirect_uri;
-    ngx_str_t                 redirect_args;
 
     SV                       *next;