com php-src: Reapply "Explicitly validate popen mode": ext/standard/file.c

From: Date: Fri, 07 Aug 2020 08:33:27 +0000
Subject: com php-src: Reapply "Explicitly validate popen mode": ext/standard/file.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-112601@lists.php.net to get a copy of this message
Commit: 3bb183036976fc8bfdf039b41efe1e4312894937 Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 5 Aug 2020 11:27:13 +0200 Parents: 7c8467562d4bc6f04047c0a32a91c95042f60f34 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3bb183036976fc8bfdf039b41efe1e4312894937 Log: 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). Changed paths: M ext/standard/file.c Diff: diff --git a/ext/standard/file.c b/ext/standard/file.c index 98578376b00..058d78688d0 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -930,8 +930,16 @@ PHP_FUNCTION(popen) 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);

« previous php.cvs (#112601) next »