File httpd-2.4.6-mod_dav-bnc864308-3-encoding.patch of Package apache2.openSUSE_13.1_Update

From: Greg Stein <gstein@gmail.com>
Date: Thu, 03 Oct 2013 06:29:35 +0100
Subject: [PATCH] mod_dav fix encoding
References: bnc#864308 https://issues.apache.org/bugzilla/show_bug.cgi?id=55397 http://svn.apache.org/viewvc?view=revision&revision=1529559 http://svn.apache.org/viewvc?view=revision&revision=1531505
Upstream: committed

Apache httpd in openSUSE 13.1 is 2.4.6. The mod_dav in this version is
problematic for Apache Subversion, the Apache httpd version will be blacklisted
in future 1.8.x releases of svn and 1.9

This patch fixes URI encoding in mod_dav.

------------------------------------------------------------------------
r1529559 | breser | 2013-10-06 02:08:51 +0100 (Sun, 06 Oct 2013) | 21 lines
Changed paths:
   M /httpd/httpd/trunk/modules/dav/fs/repos.c
   M /httpd/httpd/trunk/modules/dav/main/mod_dav.c
   M /httpd/httpd/trunk/modules/dav/main/mod_dav.h

Fix PR 55397: dav_resource->uri treated as an unparsed uri.

The change made for PR 54611 caused this field to be treated as
unescaped.  mod_dav_svn however, provided escaped URIs.  Essentially
breaking support for paths with non-URI safe characters in SVN.

Adjust the code so that dav_resource->uri is assumed to be escaped and
adjust mod_dav_fs so that it uses escaped URIs in this field.

* modules/dav/fs/repos.c
  (dav_fs_get_resource): Use the unparsed_uri to contruct the resource uri.

* modules/dav/main/mod_dav.c
  (dav_xml_escape_uri): Do not uri escape, just handle xml escaping.
  (dav_created): Assume that locn if provided is escaped.
  (dav_method_copymove, dav_method_bind): Use the unparsed_uri on the request
    when calling dav_created() to adjust to locn assuming it is escaped.

* modules/dav/main/mod_dav.h
  (dav_resource): Document that uri is escaped.

------------------------------------------------------------------------
r1531505 | breser | 2013-10-12 07:13:20 +0100 (Sat, 12 Oct 2013) | 11 lines
Changed paths:
   M /httpd/httpd/trunk/modules/dav/fs/repos.c

Followup to r1529559: mod_dav_fs: Fix encoding of hrefs in PROPFIND response.

Previous commit missed encoding the names of the children of the PROPFIND
request when the depth wasn't 0.

* modules/dav/fs/repos.c
  (dav_fs_append_uri): New function
  (dav_fs_walker): Use dav_fs_append_uri() and adjust length calculations to
    use the encoded length.


------------------------------------------------------------------------
Index: trunk/modules/dav/main/mod_dav.c
===================================================================
--- trunk/modules/dav/main/mod_dav.c	(revision 1529558)
+++ trunk/modules/dav/main/mod_dav.c	(revision 1531505)
@@ -397,11 +397,9 @@
  */
 static const char *dav_xml_escape_uri(apr_pool_t *p, const char *uri)
 {
-    const char *e_uri = ap_escape_uri(p, uri);
-
     /* check the easy case... */
-    if (ap_strchr_c(e_uri, '&') == NULL)
-        return e_uri;
+    if (ap_strchr_c(uri, '&') == NULL)
+        return uri;
 
     /* there was a '&', so more work is needed... sigh. */
 
@@ -409,7 +407,7 @@
      * Note: this is a teeny bit of overkill since we know there are no
      * '<' or '>' characters, but who cares.
      */
-    return apr_xml_quote_string(p, e_uri, 0);
+    return apr_xml_quote_string(p, uri, 0);
 }
 
 
@@ -605,7 +603,8 @@
     return DONE;
 }
 
-/* handy function for return values of methods that (may) create things */
+/* handy function for return values of methods that (may) create things.
+ * locn if provided is assumed to be escaped. */
 static int dav_created(request_rec *r, const char *locn, const char *what,
                        int replaced)
 {
@@ -613,8 +612,6 @@
 
     if (locn == NULL) {
         locn = r->unparsed_uri;
-    } else {
-        locn = ap_escape_uri(r->pool, locn);
     }
 
     /* did the target resource already exist? */
@@ -3012,7 +3009,7 @@
     }
 
     /* return an appropriate response (HTTP_CREATED or HTTP_NO_CONTENT) */
-    return dav_created(r, lookup.rnew->uri, "Destination",
+    return dav_created(r, lookup.rnew->unparsed_uri, "Destination",
                        resnew_state == DAV_RESOURCE_EXISTS);
 }
 
@@ -4618,7 +4615,7 @@
 
     /* return an appropriate response (HTTP_CREATED) */
     /* ### spec doesn't say what happens when destination was replaced */
-    return dav_created(r, lookup.rnew->uri, "Binding", 0);
+    return dav_created(r, lookup.rnew->unparsed_uri, "Binding", 0);
 }
 
 
Index: trunk/modules/dav/main/mod_dav.h
===================================================================
--- trunk/modules/dav/main/mod_dav.h	(revision 1529558)
+++ trunk/modules/dav/main/mod_dav.h	(revision 1531505)
@@ -386,7 +386,7 @@
                          * REGULAR and WORKSPACE resources,
                          * and is always 1 for WORKING */
 
-    const char *uri;    /* the URI for this resource */
+    const char *uri;    /* the escaped URI for this resource */
 
     dav_resource_private *info;         /* the provider's private info */
 
Index: trunk/modules/dav/fs/repos.c
===================================================================
--- trunk/modules/dav/fs/repos.c	(revision 1529558)
+++ trunk/modules/dav/fs/repos.c	(revision 1531505)
@@ -717,13 +717,13 @@
     resource->pool = r->pool;
 
     /* make sure the URI does not have a trailing "/" */
-    len = strlen(r->uri);
-    if (len > 1 && r->uri[len - 1] == '/') {
-        s = apr_pstrmemdup(r->pool, r->uri, len-1);
+    len = strlen(r->unparsed_uri);
+    if (len > 1 && r->unparsed_uri[len - 1] == '/') {
+        s = apr_pstrmemdup(r->pool, r->unparsed_uri, len-1);
         resource->uri = s;
     }
     else {
-        resource->uri = r->uri;
+        resource->uri = r->unparsed_uri;
     }
 
     if (r->finfo.filetype != APR_NOFILE) {
@@ -1482,6 +1482,18 @@
     return dav_fs_deleteset(info->pool, resource);
 }
 
+/* Take an unescaped path component and escape it and append it onto a
+ * dav_buffer for a URI */
+static apr_size_t dav_fs_append_uri(apr_pool_t *p, dav_buffer *pbuf,
+                                    const char *path, apr_size_t pad)
+{
+    const char *epath = ap_escape_uri(p, path);
+    apr_size_t epath_len = strlen(epath);
+
+    dav_buffer_place_mem(p, pbuf, epath, epath_len + 1, pad);
+    return epath_len;
+}
+
 /* ### move this to dav_util? */
 /* Walk recursively down through directories, *
  * including lock-null resources as we go.    */
@@ -1537,6 +1549,7 @@
     }
     while ((apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp)) == APR_SUCCESS) {
         apr_size_t len;
+        apr_size_t escaped_len;
 
         len = strlen(dirent.name);
 
@@ -1579,7 +1592,7 @@
 
         /* copy the file to the URI, too. NOTE: we will pad an extra byte
            for the trailing slash later. */
-        dav_buffer_place_mem(pool, &fsctx->uri_buf, dirent.name, len + 1, 1);
+        escaped_len = dav_fs_append_uri(pool, &fsctx->uri_buf, dirent.name, 1);
 
         /* if there is a secondary path, then do that, too */
         if (fsctx->path2.buf != NULL) {
@@ -1612,7 +1625,7 @@
             fsctx->path2.cur_len += len;
 
             /* adjust URI length to incorporate subdir and a slash */
-            fsctx->uri_buf.cur_len += len + 1;
+            fsctx->uri_buf.cur_len += escaped_len + 1;
             fsctx->uri_buf.buf[fsctx->uri_buf.cur_len - 1] = '/';
             fsctx->uri_buf.buf[fsctx->uri_buf.cur_len] = '\0';
 
@@ -1678,8 +1691,8 @@
             */
             dav_buffer_place_mem(pool, &fsctx->path1,
                                  fsctx->locknull_buf.buf + offset, len + 1, 0);
-            dav_buffer_place_mem(pool, &fsctx->uri_buf,
-                                 fsctx->locknull_buf.buf + offset, len + 1, 0);
+            dav_fs_append_uri(pool, &fsctx->uri_buf,
+                              fsctx->locknull_buf.buf + offset, 0);
             if (fsctx->path2.buf != NULL) {
                 dav_buffer_place_mem(pool, &fsctx->path2,
                                      fsctx->locknull_buf.buf + offset,
openSUSE Build Service is sponsored by