From: Antony Dovgal Date: Wed, 21 Jun 2006 13:12:37 +0000 (+0000) Subject: MFH: don't try to read or write from/to a stream if it was open in different mode... X-Git-Tag: php-5.2.0RC1~265 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c30a7f8a616729f263591bc19e6697724548868;p=php MFH: don't try to read or write from/to a stream if it was open in different mode (leads to segfault in libbz2) --- diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c index 833d6ba7ae..9df6634ecd 100644 --- a/ext/bz2/bz2.c +++ b/ext/bz2/bz2.c @@ -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; }