From: Antony Dovgal Date: Thu, 8 Dec 2005 19:53:43 +0000 (+0000) Subject: fix segfault in SplFileObject when file doesn't exist or cannot be read X-Git-Tag: RELEASE_1_0_4~463 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d5cd3efe2bd4c72ce70bec83bea0a1fafa76143f;p=php fix segfault in SplFileObject when file doesn't exist or cannot be read --- diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 6e44f730be..8265483935 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1353,16 +1353,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); } /* }}} */ @@ -1396,10 +1396,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); } /* }}} */