]> granicus.if.org Git - php/commitdiff
Fix file_get_contents segfault on empty file
authorSascha Schumann <sas@php.net>
Wed, 14 May 2003 01:08:47 +0000 (01:08 +0000)
committerSascha Schumann <sas@php.net>
Wed, 14 May 2003 01:08:47 +0000 (01:08 +0000)
ext/standard/file.c

index 35691a34e9ae5030b706d95390ec9953e59553b7..66bc863005e243d3207bd10bc0eb4714049045b7 100644 (file)
@@ -434,14 +434,15 @@ PHP_FUNCTION(file_get_contents)
        }
 
        /* uses mmap if possible */
-       if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) >= 0) {
-               
+       if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) > 0) {
                if (PG(magic_quotes_runtime)) {
                        contents = php_addslashes(contents, len, &newlen, 1 TSRMLS_CC); /* 1 = free source string */
                        len = newlen;
                }
 
                RETVAL_STRINGL(contents, len, 0);
+       } else if (len == 0) {
+               RETVAL_EMPTY_STRING();
        } else {
                RETVAL_FALSE;
        }