Skip to content

Commit

Permalink
Fixed bug #61645 (fopen and O_NONBLOCK)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
m6w6 committed Dec 6, 2013
1 parent 098d2a5 commit b5f5bff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit b5f5bff

Please sign in to comment.