Skip to content

Commit 3bb1830

Browse files
committed
Reapply "Explicitly validate popen mode"
To avoid behavior differences due to libc. This time with the check only for the non-win32 case, as Windows support additional modifiers here (t/b).
1 parent 7c84675 commit 3bb1830

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ext/standard/file.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,16 @@ PHP_FUNCTION(popen)
930930
char *z = memchr(posix_mode, 'b', mode_len);
931931
if (z) {
932932
memmove(z, z + 1, mode_len - (z - posix_mode));
933+
mode_len--;
933934
}
934935
}
936+
937+
/* Musl only partially validates the mode. Manually check it to ensure consistent behavior. */
938+
if (mode_len != 1 || (*posix_mode != 'r' && *posix_mode != 'w')) {
939+
php_error_docref2(NULL, command, posix_mode, E_WARNING, "Invalid mode");
940+
efree(posix_mode);
941+
RETURN_FALSE;
942+
}
935943
#endif
936944

937945
fp = VCWD_POPEN(command, posix_mode);

0 commit comments

Comments
 (0)