]> granicus.if.org Git - php/commitdiff
MFH: don't try to read or write from/to a stream if it was open in different mode...
authorAntony Dovgal <tony2001@php.net>
Wed, 21 Jun 2006 13:12:37 +0000 (13:12 +0000)
committerAntony Dovgal <tony2001@php.net>
Wed, 21 Jun 2006 13:12:37 +0000 (13:12 +0000)
ext/bz2/bz2.c

index 833d6ba7ae4bb9c9b02e1fc9ea46149c5dce7e7a..9df6634ecd51b43ac6c3fc60f0f4d2da5cbd7f48 100644 (file)
@@ -384,6 +384,18 @@ PHP_FUNCTION(bzopen)
 
                php_stream_from_zval(stream, file);
 
+               if (!memchr(stream->mode, Z_STRVAL_PP(mode)[0], strlen(stream->mode))) {
+                       switch (Z_STRVAL_PP(mode)[0]) {
+                               case 'r':
+                                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot read from a stream opened in write only mode");
+                                       break;
+                               case 'w':
+                                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot write to a stream opened in read only mode");
+                                       break;
+                       }
+                       RETURN_FALSE;
+               }
+
                if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_FD, (void *) &fd, REPORT_ERRORS)) {
                        RETURN_FALSE;
                }