]> git.kaiwu.me - nginx.git/commitdiff
Perl: protection against duplicate $r->sleep() calls.
authorMaxim Dounin <mdounin@mdounin.ru>
Fri, 12 Jul 2019 12:34:37 +0000 (15:34 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Fri, 12 Jul 2019 12:34:37 +0000 (15:34 +0300)
Duplicate $r->sleep() and/or $r->has_request_body() calls result
in undefined behaviour (in practice, connection leaks were observed).
To prevent this, croak() added in appropriate places.

src/http/modules/perl/nginx.xs

index 104def1e8ddf046195c343bffb75152c9b384c95..e9db2f7d6bf2422d04b37c9b9e18c00ae34b5127 100644 (file)
@@ -400,6 +400,10 @@ has_request_body(r, next)
 
     ngx_http_perl_set_request(r, ctx);
 
+    if (ctx->next) {
+        croak("has_request_body(): another handler active");
+    }
+
     if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) {
         XSRETURN_UNDEF;
     }
@@ -1093,6 +1097,10 @@ sleep(r, sleep, next)
 
     ngx_http_perl_set_request(r, ctx);
 
+    if (ctx->next) {
+        croak("sleep(): another handler active");
+    }
+
     sleep = (ngx_msec_t) SvIV(ST(1));
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,