diff options
Diffstat (limited to 'ext/standard/file.c')
-rw-r--r-- | ext/standard/file.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c index 98578376b0..88ffba8102 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -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)); |