]> granicus.if.org Git - php/commitdiff
- #48202, Out of memory error when passing non-existing filename, enable related...
authorPierre Joye <pajoye@php.net>
Mon, 25 May 2009 15:35:03 +0000 (15:35 +0000)
committerPierre Joye <pajoye@php.net>
Mon, 25 May 2009 15:35:03 +0000 (15:35 +0000)
ext/xmlwriter/php_xmlwriter.c
ext/xmlwriter/tests/xmlwriter_open_uri_error_003.phpt
ext/xmlwriter/tests/xmlwriter_open_uri_error_004.phpt
ext/xmlwriter/tests/xmlwriter_open_uri_error_005.phpt

index 773ce9144076f975cd382af3fcadfefe5bdcd8d9..c91b4d9254936e8786a666e45b80e476a44fbb0f 100644 (file)
@@ -28,7 +28,7 @@
 #include "php_ini.h"
 #include "ext/standard/info.h"
 #include "php_xmlwriter.h"
-
+#include "ext/standard/php_string.h"
 
 #if LIBXML_VERSION >= 20605
 static PHP_FUNCTION(xmlwriter_set_indent);
@@ -614,7 +614,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 (strlen(source) == 8) {
+                               return NULL;
+                       }
                        isFileUri = 1;
 #ifdef PHP_WIN32
                        source += 8;
@@ -622,6 +625,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 (strlen(source) == 17) {
+                               return NULL;
+                       }
+
                        isFileUri = 1;
 #ifdef PHP_WIN32
                        source += 17;
@@ -631,13 +638,26 @@ 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;
        }
 
index 6445edbbc06ec2d2d7c0da7d31bd60f36d060181..49a293853c69d1f1de946851df19fb3c0ab7cf73 100644 (file)
@@ -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)
index 291ae50d0575da9eeb331462b3441f41e45b1056..d4e72ffdae8c14dca065858b87fa7f5748c01777 100644 (file)
@@ -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)
index 6b71d304dc694506bbae1f941fb9ed525cd88e7f..20a28afcde96a940498087ae540e45e3938dbcf4 100644 (file)
@@ -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)