Skip to content

Commit 3892529

Browse files
committed
Close-GH 15685: improve proc_open error reporting on Windows
While similar errors are already reported via `strerror()` on other platforms, this has apparently overlooked for Windows, where only the error code has been reported so far. We adapt the affected test cases, but since there is no PHP userland function which allows us to get the current system locale, we work around. Closes GH-15687.
1 parent 7f0d257 commit 3892529

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ PHP NEWS
4242

4343
- Standard:
4444
. Fixed bug GH-15552 (Signed integer overflow in ext/standard/scanf.c). (cmb)
45+
. Implemented GH-15685 (improve proc_open error reporting on Windows). (cmb)
4546

4647
- Streams:
4748
. Fixed bug GH-15628 (php_stream_memory_get_buffer() not zero-terminated).

ext/standard/proc_open.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,9 @@ PHP_FUNCTION(proc_open)
13171317
if (newprocok == FALSE) {
13181318
DWORD dw = GetLastError();
13191319
close_all_descriptors(descriptors, ndesc);
1320-
php_error_docref(NULL, E_WARNING, "CreateProcess failed, error code: %u", dw);
1320+
char *msg = php_win32_error_to_msg(dw);
1321+
php_error_docref(NULL, E_WARNING, "CreateProcess failed: %s", msg);
1322+
php_win32_error_msg_free(msg);
13211323
goto exit_fail;
13221324
}
13231325

ext/standard/tests/general_functions/ghsa-9fcc-425m-g385_001.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ GHSA-9fcc-425m-g385 - bypass CVE-2024-1874 - batch file variation
44
<?php
55
if( substr(PHP_OS, 0, 3) != "WIN" )
66
die('skip Run only on Windows');
7+
if (!str_contains(shell_exec("does_not_exist.exe 2>&1"), "is not recognized as an internal or external command")) {
8+
die("skip English locale required");
9+
}
710
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
811
?>
912
--FILE--
@@ -49,7 +52,7 @@ operable program or batch file.
4952
'"%sghsa-9fcc-425m-g385_001.bat. ... . ."' is not recognized as an internal or external command,
5053
operable program or batch file.
5154

52-
Warning: proc_open(): CreateProcess failed, error code: 2 in %s on line %d
55+
Warning: proc_open(): CreateProcess failed: The system cannot find the file specified in %s on line %d
5356
--CLEAN--
5457
<?php
5558
@unlink(__DIR__ . '/ghsa-9fcc-425m-g385_001.bat');

ext/standard/tests/general_functions/ghsa-9fcc-425m-g385_002.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ GHSA-9fcc-425m-g385 - bypass CVE-2024-1874 - cmd.exe variation
44
<?php
55
if( substr(PHP_OS, 0, 3) != "WIN" )
66
die('skip Run only on Windows');
7+
if (!str_contains(shell_exec("does_not_exist.exe 2>&1"), "is not recognized as an internal or external command")) {
8+
die("skip English locale required");
9+
}
710
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
811
?>
912
--FILE--
@@ -49,17 +52,17 @@ $proc = proc_open(["\\cmd. ... ", "/c", $batch_file_path, "\"&notepad.exe"], $d
4952
%sghsa-9fcc-425m-g385_002.bat
5053
"&notepad.exe
5154

52-
Warning: proc_open(): CreateProcess failed, error code: 2 in %s on line %d
55+
Warning: proc_open(): CreateProcess failed: The system cannot find the file specified in %s on line %d
5356
%sghsa-9fcc-425m-g385_002.bat
5457
"&notepad.exe
5558
%sghsa-9fcc-425m-g385_002.bat
5659
"&notepad.exe
5760

58-
Warning: proc_open(): CreateProcess failed, error code: 2 in %s on line %d
61+
Warning: proc_open(): CreateProcess failed: The system cannot find the file specified in %s on line %d
5962

60-
Warning: proc_open(): CreateProcess failed, error code: 2 in %s on line %d
63+
Warning: proc_open(): CreateProcess failed: The system cannot find the file specified in %s on line %d
6164

62-
Warning: proc_open(): CreateProcess failed, error code: 2 in %s on line %d
65+
Warning: proc_open(): CreateProcess failed: The system cannot find the file specified in %s on line %d
6366
--CLEAN--
6467
<?php
6568
@unlink(__DIR__ . '/ghsa-9fcc-425m-g385_002.bat');

0 commit comments

Comments
 (0)