From: Pierre Joye Date: Mon, 25 May 2009 16:27:45 +0000 (+0000) Subject: - MFH: #48202, Out of memory error when passing non-existing filename, enable related... X-Git-Tag: php-5.2.10RC1~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88667674e243bdc3ce63d799cb494d6ddd73001d;p=php - MFH: #48202, Out of memory error when passing non-existing filename, enable related tests (marked as XFAIL now) --- diff --git a/ext/xmlwriter/php_xmlwriter.c b/ext/xmlwriter/php_xmlwriter.c index 73285f0e2f..5a3004ed69 100644 --- a/ext/xmlwriter/php_xmlwriter.c +++ b/ext/xmlwriter/php_xmlwriter.c @@ -310,7 +310,10 @@ static char *_xmlwriter_get_valid_file_path(char *source, char *resolved_path, i if (uri->scheme != NULL) { /* absolute file uris - libxml only supports localhost or empty host */ - if (strncasecmp(source, "file:///",8) == 0) { + if (strncasecmp(source, "file:///", 8) == 0) { + if (source[sizeof("file:///") - 1] == '\0') { + return NULL; + } isFileUri = 1; #ifdef PHP_WIN32 source += 8; @@ -318,6 +321,10 @@ static char *_xmlwriter_get_valid_file_path(char *source, char *resolved_path, i source += 7; #endif } else if (strncasecmp(source, "file://localhost/",17) == 0) { + if (source[sizeof("file://localhost/") - 1] == '\0') { + return NULL; + } + isFileUri = 1; #ifdef PHP_WIN32 source += 17; @@ -330,11 +337,28 @@ static char *_xmlwriter_get_valid_file_path(char *source, char *resolved_path, i file_dest = source; if ((uri->scheme == NULL || isFileUri)) { + char file_dirname[MAXPATHLEN]; + size_t dir_len; + if (!VCWD_REALPATH(source, resolved_path) && !expand_filepath(source, resolved_path TSRMLS_CC)) { xmlFreeURI(uri); return NULL; } + + memcpy(file_dirname, source, strlen(source)); + dir_len = php_dirname(file_dirname, strlen(source)); + + if (dir_len > 0) { + struct stat buf; + if (php_sys_stat(file_dirname, &buf) != 0) { + xmlFreeURI(uri); + return NULL; + } + } + file_dest = resolved_path; + } else { + file_dest = source; } xmlFreeURI(uri); diff --git a/ext/xmlwriter/tests/xmlwriter_open_uri_error_003.phpt b/ext/xmlwriter/tests/xmlwriter_open_uri_error_003.phpt index 6445edbbc0..49a293853c 100644 --- a/ext/xmlwriter/tests/xmlwriter_open_uri_error_003.phpt +++ b/ext/xmlwriter/tests/xmlwriter_open_uri_error_003.phpt @@ -10,9 +10,7 @@ var_dump(xmlwriter_open_uri('foo/bar.tmp')); Koen Kuipers koenk82@gmail.com Theo van der Zee #Test Fest Utrecht 09-05-2009 ---XFAIL-- -Getting error: xmlNewTextWriterFilename : out of memory! --EXPECTF-- -Warning: xmlwriter_open_uri(%s): failed to open stream: No such file or directory in %s on line %d +Warning: xmlwriter_open_uri(): Unable to resolve file path in %s on line %d bool(false) diff --git a/ext/xmlwriter/tests/xmlwriter_open_uri_error_004.phpt b/ext/xmlwriter/tests/xmlwriter_open_uri_error_004.phpt index 291ae50d05..d4e72ffdae 100644 --- a/ext/xmlwriter/tests/xmlwriter_open_uri_error_004.phpt +++ b/ext/xmlwriter/tests/xmlwriter_open_uri_error_004.phpt @@ -10,9 +10,7 @@ var_dump(xmlwriter_open_uri('file:///')); Koen Kuipers koenk82@gmail.com Theo van der Zee #Test Fest Utrecht 09-05-2009 ---XFAIL-- -Getting error: xmlNewTextWriterFilename : out of memory! --EXPECTF-- -Warning: xmlwriter_open_uri(/): failed to open stream: Is a directory in %s on line %d +Warning: xmlwriter_open_uri(): Unable to resolve file path in %s on line %d bool(false) diff --git a/ext/xmlwriter/tests/xmlwriter_open_uri_error_005.phpt b/ext/xmlwriter/tests/xmlwriter_open_uri_error_005.phpt index 6b71d304dc..20a28afcde 100644 --- a/ext/xmlwriter/tests/xmlwriter_open_uri_error_005.phpt +++ b/ext/xmlwriter/tests/xmlwriter_open_uri_error_005.phpt @@ -10,9 +10,7 @@ var_dump(xmlwriter_open_uri('file://localhost/')); Koen Kuipers koenk82@gmail.com Theo van der Zee #Test Fest Utrecht 09-05-2009 ---XFAIL-- -Getting error: xmlNewTextWriterFilename : out of memory! --EXPECTF-- -Warning: xmlwriter_open_uri(/): failed to open stream: Is a directory in %s on line %d +Warning: xmlwriter_open_uri(): Unable to resolve file path in %s on line %d bool(false)