Skip to content

Commit 9258123

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix stale getopt() optional value in CLI
2 parents c417dea + 893bc0a commit 9258123

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

main/getopt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct opts[], char
5757
static char **prev_optarg = NULL;
5858

5959
php_optidx = -1;
60+
if (optarg) {
61+
*optarg = NULL;
62+
}
6063

6164
if(prev_optarg && prev_optarg != optarg) {
6265
/* reset the state */

sapi/cli/tests/gh21901.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Stale getopt() optional value in CLI
3+
--FILE--
4+
<?php
5+
$php_escaped = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
6+
$cmd = $php_escaped . ' -n -d foo=bar --ini';
7+
echo shell_exec($cmd);
8+
?>
9+
--EXPECTF--
10+
Configuration File (php.ini) Path: "%S"
11+
Loaded Configuration File: "%S"
12+
Scan for additional .ini files in: %s
13+
Additional .ini files parsed: %s

0 commit comments

Comments
 (0)