]> granicus.if.org Git - php/commitdiff
MFH: fix invalid read with bzopen("","") and prevent filename from being empty (which...
authorAntony Dovgal <tony2001@php.net>
Wed, 21 Jun 2006 12:43:27 +0000 (12:43 +0000)
committerAntony Dovgal <tony2001@php.net>
Wed, 21 Jun 2006 12:43:27 +0000 (12:43 +0000)
ext/bz2/bz2.c

index 1ba7083b8a695074387df2150cf05df96dc25e1b..833d6ba7ae4bb9c9b02e1fc9ea46149c5dce7e7a 100644 (file)
@@ -359,7 +359,7 @@ PHP_FUNCTION(bzopen)
        }
        convert_to_string_ex(mode);
 
-       if (Z_STRVAL_PP(mode)[0] != 'r' && Z_STRVAL_PP(mode)[0] != 'w' && Z_STRVAL_PP(mode)[1] != '\0') {
+       if (Z_STRLEN_PP(mode) != 1 || (Z_STRVAL_PP(mode)[0] != 'r' && Z_STRVAL_PP(mode)[0] != 'w')) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", Z_STRVAL_PP(mode));
                RETURN_FALSE;
        }
@@ -367,6 +367,12 @@ PHP_FUNCTION(bzopen)
        /* If it's not a resource its a string containing the filename to open */
        if (Z_TYPE_PP(file) != IS_RESOURCE) {
                convert_to_string_ex(file);
+
+               if (Z_STRLEN_PP(file) == 0) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "filename cannot be empty");
+                       RETURN_FALSE;
+               }
+
                stream = php_stream_bz2open(NULL,
                                                                        Z_STRVAL_PP(file), 
                                                                        Z_STRVAL_PP(mode),