[php-src] PR #25663: Fix php-cgi -T N,M: use-after-free and double-free of script_file in benchmark warmup

From: Date: Mon, 23 Nov 2026 06:25:58 +0000
Subject: [php-src] PR #25663: Fix php-cgi -T N,M: use-after-free and double-free of script_file in benchmark warmup
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-40916@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25663 Author: fQwQf ## Description Two related fixes for the benchmark warmup loop in sapi/cgi: 1. do_repeat: aliased SG(request_info).path_translated = script_file. The request teardown frees path_translated, leaving script_file dangling; the warmup branch re-uses it on the next iteration (heap-use-after-free in sapi_cgi_activate() and a double-free at the next request teardown). Copy it instead, mirroring the existing estrdup(argv[php_optind]) in the sibling branch. 2. php_request_shutdown() resets the memory manager (zend_mm_shutdown(..., full=false)), which wholesale-recycles request memory. The warmup branch did not reset the getopt state like the repeats branch does, so script_file was re-used after the reset. Reset script_file/php_optind/php_optarg there as well, so each warmup iteration re-parses -f into a fresh buffer. ## Reproducer ``` php-cgi -n -f test.php -T 3,2 # before: 1 run, then "No input file specified." (or ASan UAF with # USE_ZEND_ALLOC=0), exit 255 # after: 5 runs (3 warmup + 2 measured), exit 0 ``` ## Tests sapi/cgi/tests/benchmark_warmup_repeats.phpt asserts the script executes warmup + repeats times. Verified -T 3,2 / 2,2 / 1,2 / 5 on both allocators, ASan clean.

« previous php.git-pulls (#40916) next »