Skip to content

Commit 914c1ec

Browse files
committed
Stricter validation for popen mode argument on Windows
Context: The ext/standard/tests/file/popen_pclose_error-win32.phpt test often fails under parallel testing, because the "is not recognized as an internal or external command" message doesn't actually have a guaranteed position in the output. While looking into this, I noticed that this test on Windows tests something very different (invalid comand) than on Linux (invalid mode). Here I'm adjusting the Windows popen implementation so it immediately fails on a `rw` mode, just like it does on Linux.
1 parent 427ebce commit 914c1ec

File tree

4 files changed

+9
-127
lines changed

4 files changed

+9
-127
lines changed

TSRM/tsrm_win32.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,17 +468,17 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
468468
return NULL;
469469
}
470470

471-
/*The following two checks can be removed once we drop XP support */
472471
type_len = (int)strlen(type);
473-
if (type_len <1 || type_len > 2) {
472+
if (type_len < 1 || type_len > 2) {
474473
return NULL;
475474
}
476475

477-
for (i=0; i < type_len; i++) {
478-
if (!(*ptype == 'r' || *ptype == 'w' || *ptype == 'b' || *ptype == 't')) {
479-
return NULL;
480-
}
481-
ptype++;
476+
if (ptype[0] != 'r' && ptype[0] != 'w') {
477+
return NULL;
478+
}
479+
480+
if (type_len > 1 && (ptype[1] != 'b' && ptype[1] != 't')) {
481+
return NULL;
482482
}
483483

484484
cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c ")+2);

ext/standard/tests/file/popen_pclose_error-win32-debug.phpt

Lines changed: 0 additions & 61 deletions
This file was deleted.

ext/standard/tests/file/popen_pclose_error-win32.phpt

Lines changed: 0 additions & 57 deletions
This file was deleted.

ext/standard/tests/file/popen_pclose_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Test popen() and pclose function: error conditions
33
--SKIPIF--
44
<?php
5-
if(substr(PHP_OS, 0, 3) == 'WIN' || strtoupper( substr(PHP_OS, 0, 3) ) == 'SUN')
6-
die("skip Not Valid for Windows & Sun Solaris");
5+
if (strtoupper( substr(PHP_OS, 0, 3) ) == 'SUN')
6+
die("skip Not Valid for Sun Solaris");
77
?>
88
--FILE--
99
<?php

0 commit comments

Comments
 (0)