summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Wallner <mike@php.net>2013-12-06 10:29:24 +0100
committerMichael Wallner <mike@php.net>2013-12-06 10:29:24 +0100
commitb5f5bff965c1a27a4820d0129d61f80ef8894e38 (patch)
treea443003ac2871d7b498523e9f825d801c04ae478
parent098d2a5d0ff6353602654a9872c76c5811277546 (diff)
downloadphp-git-b5f5bff965c1a27a4820d0129d61f80ef8894e38.tar.gz
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
-rw-r--r--NEWS1
-rw-r--r--main/streams/plain_wrapper.c12
2 files changed, 8 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index c0379f82b3..c601a8af77 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 4ee81506b3..c188763f53 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -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;