~ubuntu-branches/ubuntu/trusty/apache2/trusty

« back to all changes in this revision

Viewing changes to debian/patches/073_mod_dav_trunk_fixes.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-05-05 01:28:04 UTC
  • mfrom: (14.3.15 sid)
  • Revision ID: james.westby@ubuntu.com-20100505012804-vbouq0xs3tu2vvij
Tags: 2.2.15-5ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/{control, rules}: Enable PIE hardening.
  - debian/{control, rules, apache2.2-common.ufw.profile}: Add ufw profiles.
  - debian/control: Add bzr tag and point it to our tree.
  - debian/apache2-2.common.apache2.init: Add graceful restart (LP: #456381)
  + Dropped:
    - debian/patches/206-fix-potential-memory-leaks.dpatch: No longer needed.
    - debian/patches/206-report-max-client-mpm-worker.dpatch: No longer needed.
    - debian/config-dir/apache2.conf: Merged back from debian.
    - mod-reqtimeout functionality: Merge back from debian.
    - debian/patches/204_CVE-2010-0408.dpatch: No longer needed.
    - debian/patches/205_CVE-2010-0434.dpatch: No longer needed.
    - debian/patches/203_fix-ab-segfault.dpatch: No longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
##
3
3
## All lines beginning with `## DP:' are a description of the patch.
4
4
## DP: Various bug fixes for mod_dav/mod_dav_fs
5
 
## DP: upstream svn revs 834018:835092 in modules/dav
6
 
#
7
 
# *) mod_dav: Include uri when logging a PUT error due to connection abort.
8
 
#    PR 38149. [Stefan Fritsch]
9
 
#
10
 
# *) mod_dav: Return 409 instead of 500 for a LOCK request if the parent
11
 
#    resource does not exist or is not a collection. PR 43465. [Stefan Fritsch]
12
 
#
13
 
# *) mod_dav_fs: Return 409 instead of 500 for Litmus test case copy_nodestcoll
14
 
#    (a COPY request where the parent of the destination resource does not
15
 
#    exist). PR 39299. [Stefan Fritsch]
16
 
#
17
 
# *) mod_dav_fs: Don't delete the whole file if a PUT with content-range failed.
18
 
#    PR 42896. [Stefan Fritsch]
19
 
#
20
 
# *) mod_dav_fs: Make PUT create files atomically and no longer destroy the
21
 
#    old file if the transfer aborted. PR 39815. [Paul Querna, Stefan Fritsch]
22
 
#
23
 
# *) mod_dav_fs: Remove inode keyed locking as this conflicts with atomically
24
 
#    creating files. On systems with inode numbers, this is a format change of
25
 
#    the DavLockDB. The old DavLockDB must be deleted on upgrade.
26
 
#    [Stefan Fritsch]
 
5
## DP: upstream svn revs 834018:835092 and 928403 in modules/dav
 
6
## DP:
 
7
## DP: *) mod_dav: Include uri when logging a PUT error due to connection abort.
 
8
## DP:    PR 38149. [Stefan Fritsch]
 
9
## DP:
 
10
## DP: *) mod_dav: Return 409 instead of 500 for a LOCK request if the parent
 
11
## DP:    resource does not exist or is not a collection. PR 43465. [Stefan Fritsch]
 
12
## DP:
 
13
## DP: *) mod_dav_fs: Return 409 instead of 500 for Litmus test case copy_nodestcoll
 
14
## DP:    (a COPY request where the parent of the destination resource does not
 
15
## DP:    exist). PR 39299. [Stefan Fritsch]
 
16
## DP:
 
17
## DP: *) mod_dav_fs: Don't delete the whole file if a PUT with content-range failed.
 
18
## DP:    PR 42896. [Stefan Fritsch]
 
19
## DP:
 
20
## DP: *) mod_dav_fs: Make PUT create files atomically and no longer destroy the
 
21
## DP:    old file if the transfer aborted. PR 39815. [Paul Querna, Stefan Fritsch]
 
22
## DP:
 
23
## DP: *) mod_dav_fs: Remove inode keyed locking as this conflicts with atomically
 
24
## DP:    creating files. On systems with inode numbers, this is a format change of
 
25
## DP:    the DavLockDB. The old DavLockDB must be deleted on upgrade.
 
26
## DP:    [Stefan Fritsch]
27
27
@DPATCH@
28
 
Index: a/modules/dav/main/mod_dav.c
29
 
===================================================================
30
 
--- a/modules/dav/main/mod_dav.c        (Revision 834018)
31
 
+++ a/modules/dav/main/mod_dav.c        (Revision 835089)
32
 
@@ -982,7 +982,10 @@
33
 
 
34
 
             if (rc != APR_SUCCESS) {
35
 
                 err = dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
36
 
-                                    "Could not get next bucket brigade");
37
 
+                                    apr_psprintf(r->pool,
38
 
+                                                 "Could not get next bucket "
39
 
+                                                 "brigade (URI: %s)",
40
 
+                                                 ap_escape_html(r->pool, r->uri)));
41
 
                 break;
42
 
             }
43
 
 
44
 
@@ -1005,8 +1008,10 @@
45
 
                 rc = apr_bucket_read(b, &data, &len, APR_BLOCK_READ);
46
 
                 if (rc != APR_SUCCESS) {
47
 
                     err = dav_new_error(r->pool, HTTP_BAD_REQUEST, 0,
48
 
-                                        "An error occurred while reading "
49
 
-                                        "the request body.");
50
 
+                                        apr_psprintf(r->pool,
51
 
+                                                    "An error occurred while reading"
52
 
+                                                    " the request body (URI: %s)",
53
 
+                                                    ap_escape_html(r->pool, r->uri)));
54
 
                     break;
55
 
                 }
56
 
 
57
 
@@ -2995,6 +3000,7 @@
58
 
 {
59
 
     dav_error *err;
60
 
     dav_resource *resource;
61
 
+    dav_resource *parent;
62
 
     const dav_hooks_locks *locks_hooks;
63
 
     int result;
64
 
     int depth;
65
 
@@ -3026,6 +3032,20 @@
66
 
     if (err != NULL)
67
 
         return dav_handle_err(r, err, NULL);
68
 
 
69
 
+    /* Check if parent collection exists */
70
 
+    if ((err = resource->hooks->get_parent_resource(resource, &parent)) != NULL) {
71
 
+        /* ### add a higher-level description? */
72
 
+        return dav_handle_err(r, err, NULL);
73
 
+    }
74
 
+    if (parent && (!parent->exists || parent->collection != 1)) {
75
 
+        err = dav_new_error(r->pool, HTTP_CONFLICT, 0,
76
 
+                           apr_psprintf(r->pool,
77
 
+                                        "The parent resource of %s does not "
78
 
+                                        "exist or is not a collection.", 
79
 
+                                        ap_escape_html(r->pool, r->uri)));
80
 
+        return dav_handle_err(r, err, NULL);
81
 
+    }
82
 
+
83
 
     /*
84
 
      * Open writable. Unless an error occurs, we'll be
85
 
      * writing into the database.
86
 
Index: a/modules/dav/fs/lock.c
87
 
===================================================================
88
 
--- a/modules/dav/fs/lock.c     (Revision 834018)
89
 
+++ a/modules/dav/fs/lock.c     (Revision 835089)
 
28
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' trunk~/modules/dav/fs/lock.c trunk/modules/dav/fs/lock.c
 
29
--- trunk~/modules/dav/fs/lock.c        2010-03-29 21:46:51.000000000 +0200
 
30
+++ trunk/modules/dav/fs/lock.c 2010-03-29 21:49:00.970983302 +0200
90
31
@@ -48,9 +48,8 @@
91
32
 **
92
33
 ** KEY
228
169
     return NULL;
229
170
 }
230
171
 
231
 
Index: a/modules/dav/fs/repos.c
232
 
===================================================================
233
 
--- a/modules/dav/fs/repos.c    (Revision 834018)
234
 
+++ a/modules/dav/fs/repos.c    (Revision 835089)
235
 
@@ -140,6 +140,11 @@
 
172
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' trunk~/modules/dav/fs/repos.c trunk/modules/dav/fs/repos.c
 
173
--- trunk~/modules/dav/fs/repos.c       2010-03-29 21:46:51.000000000 +0200
 
174
+++ trunk/modules/dav/fs/repos.c        2010-03-29 21:49:08.031078314 +0200
 
175
@@ -27,6 +27,10 @@
 
176
 #include <stdio.h>              /* for sprintf() */
 
177
 #endif
 
178
 
 
179
+#if APR_HAVE_UNISTD_H
 
180
+#include <unistd.h>             /* for getpid() */
 
181
+#endif
 
182
+
 
183
 #include "httpd.h"
 
184
 #include "http_log.h"
 
185
 #include "http_protocol.h"      /* for ap_set_* (in dav_fs_set_headers) */
 
186
@@ -139,6 +143,11 @@
236
187
 */
237
188
 #define DAV_PROPID_FS_executable        1
238
189
 
239
190
+/*
240
191
+ * prefix for temporary files
241
192
+ */
242
 
+#define DAV_FS_TMP_PREFIX ".davfs." 
 
193
+#define DAV_FS_TMP_PREFIX ".davfs.tmp" 
243
194
+
244
195
 static const dav_liveprop_spec dav_fs_props[] =
245
196
 {
246
197
     /* standard DAV properties */
247
 
@@ -192,11 +197,14 @@
 
198
@@ -191,11 +200,14 @@
248
199
     apr_pool_t *p;
249
200
     apr_file_t *f;
250
201
     const char *pathname;       /* we may need to remove it at close time */
259
210
                         HTTP_INTERNAL_SERVER_ERROR)
260
211
 
261
212
 /* forward declaration for internal treewalkers */
262
 
@@ -420,11 +428,24 @@
 
213
@@ -414,11 +426,24 @@
263
214
     apr_file_close(inf);
264
215
     apr_file_close(outf);
265
216
 
286
237
             /* ### ACK. this creates an inconsistency. do more!? */
287
238
 
288
239
             /* ### use something besides 500? */
289
 
@@ -506,9 +527,13 @@
 
240
@@ -500,9 +525,13 @@
290
241
     dst = apr_pstrcat(p, dst, "/", dst_file, NULL);
291
242
 
292
243
     /* copy/move the file now */
303
254
             /* ### use something besides 500? */
304
255
             return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
305
256
                                  "Could not move state file.");
306
 
@@ -848,6 +873,14 @@
 
257
@@ -841,6 +870,34 @@
307
258
             && ctx2->pathname[len1] == '/');
308
259
 }
309
260
 
315
266
+        return APR_SUCCESS;
316
267
+}
317
268
+
 
269
+/* custom mktemp that creates the file with APR_OS_DEFAULT permissions */
 
270
+static apr_status_t dav_fs_mktemp(apr_file_t **fp, char *templ, apr_pool_t *p)
 
271
+{
 
272
+    apr_status_t rv;
 
273
+    int num = ((getpid() << 7) + (int)templ % (1 << 16) ) % ( 1 << 23 ) ;
 
274
+    char *numstr = templ + strlen(templ) - 6;
 
275
+
 
276
+    ap_assert(numstr >= templ);
 
277
+
 
278
+    do {
 
279
+        num = (num + 1) % ( 1 << 23 );
 
280
+        snprintf(numstr, 7, "%06x", num);
 
281
+        rv = apr_file_open(fp, templ,
 
282
+                           APR_WRITE | APR_CREATE | APR_BINARY | APR_EXCL,
 
283
+                           APR_OS_DEFAULT, p);
 
284
+    } while (APR_STATUS_IS_EEXIST(rv));
 
285
+        
 
286
+    return rv;
 
287
+}
 
288
+
318
289
 static dav_error * dav_fs_open_stream(const dav_resource *resource,
319
290
                                       dav_stream_mode mode,
320
291
                                       dav_stream **stream)
321
 
@@ -872,7 +905,32 @@
 
292
@@ -865,7 +922,32 @@
322
293
 
323
294
     ds->p = p;
324
295
     ds->pathname = resource->info->pathname;
329
300
+    if (mode == DAV_MODE_WRITE_TRUNC) {
330
301
+        ds->temppath = apr_pstrcat(p, ap_make_dirstr_parent(p, ds->pathname),
331
302
+                                   DAV_FS_TMP_PREFIX "XXXXXX", NULL);
332
 
+        rv = apr_file_mktemp(&ds->f, ds->temppath, flags, ds->p);
 
303
+        rv = dav_fs_mktemp(&ds->f, ds->temppath, ds->p);
333
304
+        apr_pool_cleanup_register(p, ds, tmpfile_cleanup,
334
305
+                                  apr_pool_cleanup_null);
335
306
+    }
352
323
     if (rv != APR_SUCCESS) {
353
324
         return dav_new_error(p, MAP_IO2HTTP(rv), 0,
354
325
                              "An error occurred while opening a resource.");
355
 
@@ -886,17 +944,33 @@
 
326
@@ -879,17 +961,33 @@
356
327
 
357
328
 static dav_error * dav_fs_close_stream(dav_stream *stream, int commit)
358
329
 {
369
340
-                                 "when it was being closed.");
370
341
+        if (stream->temppath) {
371
342
+            apr_pool_cleanup_run(stream->p, stream, tmpfile_cleanup);
372
 
         }
 
343
+        }
373
344
+        else if (stream->unlink_on_error) {
374
345
+            if (apr_file_remove(stream->pathname, stream->p) != APR_SUCCESS) {
375
346
+                /* ### use a better description? */
378
349
+                                     "back) the resource "
379
350
+                                     "when it was being closed.");
380
351
+            }
381
 
+        }
 
352
         }
382
353
     }
383
354
+    else if (stream->temppath) {
384
355
+        rv = apr_file_rename(stream->temppath, stream->pathname, stream->p);
392
363
 
393
364
     return NULL;
394
365
 }
395
 
@@ -1204,7 +1278,7 @@
 
366
@@ -1201,7 +1299,7 @@
396
367
     dav_resource_private *srcinfo = src->info;
397
368
     dav_resource_private *dstinfo = dst->info;
398
369
     dav_error *err;
401
372
 
402
373
 #if DAV_DEBUG
403
374
     if (src->hooks != dst->hooks) {
404
 
@@ -1218,39 +1292,12 @@
 
375
@@ -1215,39 +1313,12 @@
405
376
     }
406
377
 #endif
407
378
 
444
415
         if ((err = dav_fs_copymove_resource(1, src, dst, DAV_INFINITY,
445
416
                                             response)) == NULL) {
446
417
             /* update resource states */
447
 
@@ -1263,20 +1310,16 @@
 
418
@@ -1260,20 +1331,16 @@
448
419
         return err;
449
420
     }
450
421
 
467
438
     dst->exists = 1;
468
439
     dst->collection = src->collection;
469
440
     src->exists = 0;
470
 
@@ -1478,14 +1521,18 @@
 
441
@@ -1475,14 +1542,18 @@
471
442
             /* ### need to authorize each file */
472
443
             /* ### example: .htaccess is normally configured to fail auth */
473
444
 
490
461
             continue;
491
462
         }
492
463
 
 
464
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' trunk~/modules/dav/main/mod_dav.c trunk/modules/dav/main/mod_dav.c
 
465
--- trunk~/modules/dav/main/mod_dav.c   2010-03-29 21:46:51.000000000 +0200
 
466
+++ trunk/modules/dav/main/mod_dav.c    2010-03-29 21:49:00.966964568 +0200
 
467
@@ -986,7 +986,10 @@
 
468
 
 
469
             if (rc != APR_SUCCESS) {
 
470
                 err = dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
 
471
-                                    "Could not get next bucket brigade");
 
472
+                                    apr_psprintf(r->pool,
 
473
+                                                 "Could not get next bucket "
 
474
+                                                 "brigade (URI: %s)",
 
475
+                                                 ap_escape_html(r->pool, r->uri)));
 
476
                 break;
 
477
             }
 
478
 
 
479
@@ -1009,8 +1012,10 @@
 
480
                 rc = apr_bucket_read(b, &data, &len, APR_BLOCK_READ);
 
481
                 if (rc != APR_SUCCESS) {
 
482
                     err = dav_new_error(r->pool, HTTP_BAD_REQUEST, 0,
 
483
-                                        "An error occurred while reading "
 
484
-                                        "the request body.");
 
485
+                                        apr_psprintf(r->pool,
 
486
+                                                    "An error occurred while reading"
 
487
+                                                    " the request body (URI: %s)",
 
488
+                                                    ap_escape_html(r->pool, r->uri)));
 
489
                     break;
 
490
                 }
 
491
 
 
492
@@ -2966,6 +2971,7 @@
 
493
 {
 
494
     dav_error *err;
 
495
     dav_resource *resource;
 
496
+    dav_resource *parent;
 
497
     const dav_hooks_locks *locks_hooks;
 
498
     int result;
 
499
     int depth;
 
500
@@ -2997,6 +3003,20 @@
 
501
     if (err != NULL)
 
502
         return dav_handle_err(r, err, NULL);
 
503
 
 
504
+    /* Check if parent collection exists */
 
505
+    if ((err = resource->hooks->get_parent_resource(resource, &parent)) != NULL) {
 
506
+        /* ### add a higher-level description? */
 
507
+        return dav_handle_err(r, err, NULL);
 
508
+    }
 
509
+    if (parent && (!parent->exists || parent->collection != 1)) {
 
510
+        err = dav_new_error(r->pool, HTTP_CONFLICT, 0,
 
511
+                           apr_psprintf(r->pool,
 
512
+                                        "The parent resource of %s does not "
 
513
+                                        "exist or is not a collection.", 
 
514
+                                        ap_escape_html(r->pool, r->uri)));
 
515
+        return dav_handle_err(r, err, NULL);
 
516
+    }
 
517
+
 
518
     /*
 
519
      * Open writable. Unless an error occurs, we'll be
 
520
      * writing into the database.