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).
char *z = memchr(posix_mode, 'b', mode_len);
if (z) {
memmove(z, z + 1, mode_len - (z - posix_mode));
+ mode_len--;
}
}
+
+ /* 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;
+ }
#endif
fp = VCWD_POPEN(command, posix_mode);