[nginx-tests] Tests: perl invalid request object tests.

Maxim Dounin mdounin at mdounin.ru
Mon Jul 6 04:46:27 UTC 2026


details:   http://freenginx.org/hg/nginx-tests/rev/e35d7a7d58e2
branches:  
changeset: 2077:e35d7a7d58e2
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Mon Jul 06 07:15:12 2026 +0300
description:
Tests: perl invalid request object tests.

diffstat:

 perl_refcount.t |  43 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 42 insertions(+), 1 deletions(-)

diffs (65 lines):

diff --git a/perl_refcount.t b/perl_refcount.t
--- a/perl_refcount.t
+++ b/perl_refcount.t
@@ -22,7 +22,7 @@ use Test::Nginx;
 select STDERR; $| = 1;
 select STDOUT; $| = 1;
 
-my $t = Test::Nginx->new()->has(qw/http perl/)->plan(4)
+my $t = Test::Nginx->new()->has(qw/http perl/)->plan(6)
 	->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
@@ -85,6 +85,27 @@ http {
                 return OK;
             }';
         }
+
+        location /stale {
+            perl 'sub {
+                my $r = shift;
+                $prev->log_error(0, "next request arrived") if $prev;
+                $r->send_http_header;
+                $prev->print("print to stale request") if $prev;
+                $prev = $r;
+                return OK;
+            }';
+        }
+
+        location /bless {
+            perl 'sub {
+                my $v = 10;
+                my $r = bless \$v, "nginx";
+                $r->send_http_header;
+                $r->print("it works");
+                return OK;
+            }';
+        }
     }
 }
 
@@ -121,4 +142,24 @@ like(http_get('/redirect'), qr/works/, '
 
 }
 
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.31.3');
+todo_skip 'might coredump', 2 unless $t->has_version('1.31.3')
+	or $ENV{TEST_NGINX_UNSAFE};
+
+# the $r request object might be preserved by the code,
+# and usage of such invalid request objects needs to be prevented;
+# note though that the stale request might happen to match the active one
+
+http_get('/stale');
+like(http_get('/stale'), qr/500 Internal|stale request/,
+	'stale request object');
+
+# similarly, if the request object is constructed with bless()
+# with an incorrect pointer, it should be rejected
+
+like(http_get('/bless'), qr/500 Internal/, 'invalid request object');
+
+}
+
 ###############################################################################


More information about the nginx-devel mailing list