summaryrefslogtreecommitdiff
path: root/ext/bz2
diff options
context:
space:
mode:
authorAntony Dovgal <tony2001@php.net>2006-06-21 13:12:37 +0000
committerAntony Dovgal <tony2001@php.net>2006-06-21 13:12:37 +0000
commit8c30a7f8a616729f263591bc19e6697724548868 (patch)
tree49f331d76c7e105bd560be63dad4aa687cf61889 /ext/bz2
parente7439fa200af3949b4e4fd55b24ce91e2aeb2968 (diff)
downloadphp-git-8c30a7f8a616729f263591bc19e6697724548868.tar.gz
MFH: don't try to read or write from/to a stream if it was open in different mode (leads to segfault in libbz2)
Diffstat (limited to 'ext/bz2')
-rw-r--r--ext/bz2/bz2.c12
1 files changed, 12 insertions, 0 deletions
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;
}