applied cleanup patch from Mikhail Zabaluev which should finish fixing
authorDaniel Veillard <veillard@src.gnome.org>
Wed, 11 Oct 2006 09:16:27 +0000 (09:16 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Wed, 11 Oct 2006 09:16:27 +0000 (09:16 +0000)
* libxslt/security.c: applied cleanup patch from Mikhail Zabaluev
  which should finish fixing #337486
Daniel

ChangeLog
libxslt/security.c

index c194d6d..0ff9233 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Oct 11 11:16:34 CEST 2006 Daniel Veillard <daniel@veillard.com>
+
+       * libxslt/security.c: applied cleanup patch from Mikhail Zabaluev
+         which should finish fixing #337486
+
 Wed Oct 11 09:55:06 CEST 2006 Daniel Veillard <daniel@veillard.com>
 
        * libxslt/security.c: applied fix from Shane Corgatelli to pass
index 8002fd6..6376f20 100644 (file)
@@ -280,6 +280,57 @@ xsltCheckFilename (const char *path)
     return 1;
 }
 
+static int
+xsltCheckWritePath(xsltSecurityPrefsPtr sec,
+                  xsltTransformContextPtr ctxt,
+                  const char *path)
+{
+    int ret;
+    xsltSecurityCheck check;
+    char *directory;
+
+    check = xsltGetSecurityPrefs(sec, XSLT_SECPREF_WRITE_FILE);
+    if (check != NULL) {
+       ret = check(sec, ctxt, path);
+       if (ret == 0) {
+           xsltTransformError(ctxt, NULL, NULL,
+                              "File write for %s refused\n", path);
+           return(0);
+       }
+    }
+
+    directory = xmlParserGetDirectory (path);
+
+    if (directory != NULL) {
+       ret = xsltCheckFilename(directory);
+       if (ret == 0) {
+           /*
+            * The directory doesn't exist check for creation
+            */
+           check = xsltGetSecurityPrefs(sec,
+                                        XSLT_SECPREF_CREATE_DIRECTORY);
+           if (check != NULL) {
+               ret = check(sec, ctxt, directory);
+               if (ret == 0) {
+                   xsltTransformError(ctxt, NULL, NULL,
+                                      "Directory creation for %s refused\n",
+                                      path);
+                   xmlFree(directory);
+                   return(0);
+               }
+           }
+           ret = xsltCheckWritePath(sec, ctxt, directory);
+           if (ret == 1)
+               ret = mkdir(directory, 0755);
+       }
+       xmlFree(directory);
+       if (ret < 0)
+           return(ret);
+    }
+
+    return(1);
+}
+
 /**
  * xsltCheckWrite:
  * @sec:  the security options
@@ -310,49 +361,14 @@ xsltCheckWrite(xsltSecurityPrefsPtr sec,
     }
     if ((uri->scheme == NULL) ||
        (xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) {
-       char *directory;
 
        /*
         * Check if we are allowed to write this file
         */
-       check = xsltGetSecurityPrefs(sec, XSLT_SECPREF_WRITE_FILE);
-       if (check != NULL) {
-           ret = check(sec, ctxt, uri->path);
-           if (ret == 0) {
-               xsltTransformError(ctxt, NULL, NULL,
-                            "File write for %s refused\n", URL);
-               xmlFreeURI(uri);
-               return(0);
-           }
-       }
-
-       directory = xmlParserGetDirectory (uri->path);
-       if (directory != NULL) {
-           ret = xsltCheckFilename(directory);
-           if (ret == 0) {
-               /*
-                * The directory doesn't exist check for creation
-                */
-               check = xsltGetSecurityPrefs(sec,
-                                XSLT_SECPREF_CREATE_DIRECTORY);
-               if (check != NULL) {
-                   ret = check(sec, ctxt, directory);
-                   if (ret == 0) {
-                       xsltTransformError(ctxt, NULL, NULL,
-                                        "Directory creation for %s refused\n",
-                                        URL);
-                       xmlFree(directory);
-                       xmlFreeURI(uri);
-                       return(0);
-                   }
-               }
-               ret = xsltCheckWrite(sec, ctxt, (const xmlChar *)directory);
-               if (ret == 1)
-                   ret = mkdir(directory, 0755);
-               if (ret < 0)
-                   return(ret);
-           }
-           xmlFree(directory);
+       ret = xsltCheckWritePath(sec, ctxt, uri->path);
+       if (ret <= 0) {
+           xmlFreeURI(uri);
+           return(ret);
        }
     } else {
        /*