[PATCH 4 of 4] Tests: access_log variable evaluation tests

Maxim Dounin mdounin at mdounin.ru
Mon Jun 8 17:46:42 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1780936534 -10800
#      Mon Jun 08 19:35:34 2026 +0300
# Node ID 2cbaa4b88c1dc8a7c3b329c220daa4e5a9c92b18
# Parent  e2ccdc5e3d031950a1a833b372791812902cc365
Tests: access_log variable evaluation tests.

The access log module uses its own script engine, which, however,
suffers from similar issues when trying to use variables with side
effects, or non-cacheable variables along with variables which use
ngx_http_script_run() and therefore flush all other non-cacheable
variables ($document_root, $realpath_root).

diff --git a/access_log_script.t b/access_log_script.t
new file mode 100644
--- /dev/null
+++ b/access_log_script.t
@@ -0,0 +1,95 @@
+#!/usr/bin/perl
+
+# (C) Maxim Dounin
+
+# Tests for access_log, script execution.
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+my $t = Test::Nginx->new()->has(qw/http rewrite map/)->plan(2)
+	->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+http {
+    %%TEST_GLOBALS_HTTP%%
+
+    log_format map_capture "start $capture $map_capture end";
+    log_format map_volatile
+               "start $map_volatile $document_root $realpath_root end";
+
+    map $uri $map_capture {
+        ~(?<capture>.*) $capture;
+    }
+
+    map prefix:$capture $map_volatile {
+        volatile;
+        ~(?<capture>.*) $capture;
+    }
+
+    server {
+        listen       127.0.0.1:8080;
+        server_name  localhost;
+
+        location /map {
+            access_log %%TESTDIR%%/map.log map_capture;
+        }
+
+        location /map_volatile {
+            root html/$pid;
+            access_log %%TESTDIR%%/map.log map_volatile;
+        }
+    }
+}
+
+EOF
+
+$t->run();
+
+###############################################################################
+
+TODO: {
+todo_skip 'might coredump', 2
+	unless $ENV{TEST_NGINX_UNSAFE};
+local $TODO = 'not yet';
+
+# map with side effects might result in incorrect buffer size
+# and buffer overrun
+
+http_get('/map');
+
+# using a non-cacheable variable might result in incorrect buffer
+# size and buffer overrun
+
+http_get('/map_volatile');
+
+$t->stop();
+
+my $log = $t->read_file('map.log');
+
+like($log, qr!start /map /map end!, 'log and map with side effects');
+like($log, qr!start prefix: .* end!, 'log and volatile map');
+
+}
+
+###############################################################################



More information about the nginx-devel mailing list