mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Explicitly validate popen mode
To avoid behavior differences due to libc.
This commit is contained in:
parent
0dda242bde
commit
ab36540bdd
2 changed files with 9 additions and 1 deletions
|
@ -930,10 +930,18 @@ PHP_FUNCTION(popen)
|
|||
char *z = memchr(posix_mode, 'b', mode_len);
|
||||
if (z) {
|
||||
memmove(z, z + 1, mode_len - (z - posix_mode));
|
||||
mode_len--;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Musl only partially validates the mode. Manually check it to ensure consistent behavior. */
|
||||
if (mode_len != 1 || (*posix_mode != 'r' && *posix_mode != 'w')) {
|
||||
php_error_docref2(NULL, command, posix_mode, E_WARNING, "Invalid mode");
|
||||
efree(posix_mode);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
fp = VCWD_POPEN(command, posix_mode);
|
||||
if (!fp) {
|
||||
php_error_docref2(NULL, command, posix_mode, E_WARNING, "%s", strerror(errno));
|
||||
|
|
|
@ -22,7 +22,7 @@ unlink($file_path."/popen.tmp");
|
|||
--EXPECTF--
|
||||
*** Testing for error conditions ***
|
||||
|
||||
Warning: popen(abc.txt,rw): %s on line %d
|
||||
Warning: popen(abc.txt,rw): Invalid mode in %s on line %d
|
||||
bool(false)
|
||||
|
||||
--- Done ---
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue