Fixed bug #61645 (fopen and O_NONBLOCK)

if a mode like "rn" was passed to fopen(), then
php_stream_parse_fopen_modes() would assign O_WRONLY to
flags, because O_NONBLOCK tainted flags for the r/w/+ check
This commit is contained in:
Michael Wallner 2013-12-06 10:29:24 +01:00
parent 098d2a5d0f
commit b5f5bff965
2 changed files with 8 additions and 5 deletions

1
NEWS
View File

@ -4,6 +4,7 @@ PHP NEWS
- Core:
. Added validation of class names in the autoload process. (Dmitry)
. Fixed bug #61645 (fopen and O_NONBLOCK). (Mike)
- Date:
. Fixed bug #66060 (Heap buffer over-read in DateInterval). (Remi)

View File

@ -78,11 +78,7 @@ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags)
/* unknown mode */
return FAILURE;
}
#if defined(O_NONBLOCK)
if (strchr(mode, 'n')) {
flags |= O_NONBLOCK;
}
#endif
if (strchr(mode, '+')) {
flags |= O_RDWR;
} else if (flags) {
@ -91,6 +87,12 @@ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags)
flags |= O_RDONLY;
}
#if defined(O_NONBLOCK)
if (strchr(mode, 'n')) {
flags |= O_NONBLOCK;
}
#endif
#if defined(_O_TEXT) && defined(O_BINARY)
if (strchr(mode, 't')) {
flags |= _O_TEXT;