]> granicus.if.org Git - php/commitdiff
MFH: fix segfault in SplFileObject when file doesn't exist or cannot be read
authorAntony Dovgal <tony2001@php.net>
Thu, 8 Dec 2005 19:55:13 +0000 (19:55 +0000)
committerAntony Dovgal <tony2001@php.net>
Thu, 8 Dec 2005 19:55:13 +0000 (19:55 +0000)
ext/spl/spl_directory.c

index 5349c33d34750fe09480273f207db7d042b8559d..f927d865937b6f43c37a81c8764b2dee0c9278d7 100755 (executable)
@@ -1357,16 +1357,16 @@ SPL_METHOD(SplFileObject, __construct)
                return;
        }
        
-       spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC);
-
-       p1 = strrchr(intern->file_name, '/');
-       p2 = strrchr(intern->file_name, '\\');
-       if (p1 || p2) {
-               intern->path_len = (p1 > p2 ? p1 : p2) - intern->file_name;
-       } else {
-               intern->path_len = 0;
+       if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == SUCCESS) {
+               p1 = strrchr(intern->file_name, '/');
+               p2 = strrchr(intern->file_name, '\\');
+               if (p1 || p2) {
+                       intern->path_len = (p1 > p2 ? p1 : p2) - intern->file_name;
+               } else {
+                       intern->path_len = 0;
+               }
+               intern->path = estrndup(intern->file_name, intern->path_len);
        }
-       intern->path = estrndup(intern->file_name, intern->path_len);
 
        php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
 } /* }}} */
@@ -1400,10 +1400,10 @@ SPL_METHOD(SplTempFileObject, __construct)
        intern->u.file.open_mode_len = 1;
        intern->u.file.zcontext = NULL;
        
-       spl_filesystem_file_open(intern, 0, 0 TSRMLS_CC);
-
-       intern->path_len = 0;
-       intern->path = estrndup("", 0);
+       if (spl_filesystem_file_open(intern, 0, 0 TSRMLS_CC) == SUCCESS) {
+               intern->path_len = 0;
+               intern->path = estrndup("", 0);
+       }
 
        php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
 } /* }}} */