From 0d1efb245b26b73d5a68c0b2e5692ca61f65aff9 Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Thu, 8 Dec 2005 19:55:13 +0000 Subject: [PATCH] MFH: fix segfault in SplFileObject when file doesn't exist or cannot be read --- ext/spl/spl_directory.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index 5349c33d34..f927d86593 100755 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -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); } /* }}} */ -- 2.40.0