Skip to content

Commit b5f5bff

Browse files
committed
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
1 parent 098d2a5 commit b5f5bff

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44

55
- Core:
66
. Added validation of class names in the autoload process. (Dmitry)
7+
. Fixed bug #61645 (fopen and O_NONBLOCK). (Mike)
78

89
- Date:
910
. Fixed bug #66060 (Heap buffer over-read in DateInterval). (Remi)

main/streams/plain_wrapper.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags)
7878
/* unknown mode */
7979
return FAILURE;
8080
}
81-
#if defined(O_NONBLOCK)
82-
if (strchr(mode, 'n')) {
83-
flags |= O_NONBLOCK;
84-
}
85-
#endif
81+
8682
if (strchr(mode, '+')) {
8783
flags |= O_RDWR;
8884
} else if (flags) {
@@ -91,6 +87,12 @@ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags)
9187
flags |= O_RDONLY;
9288
}
9389

90+
#if defined(O_NONBLOCK)
91+
if (strchr(mode, 'n')) {
92+
flags |= O_NONBLOCK;
93+
}
94+
#endif
95+
9496
#if defined(_O_TEXT) && defined(O_BINARY)
9597
if (strchr(mode, 't')) {
9698
flags |= _O_TEXT;

0 commit comments

Comments
 (0)