mirror of
https://github.com/php/php-src.git
synced 2026-04-03 14:12:38 +02:00
Explicitly validate popen mode
To avoid behavior differences due to libc.
This commit is contained in:
@@ -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 ---
|
||||
|
||||
Reference in New Issue
Block a user