From f4cb07f72350b1d0a09f3220b7ae241606390054 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Wed, 13 Apr 2016 00:23:31 -0400 Subject: [PATCH] [mod_webdav] readdir POSIX compat (fixes #1826) do not expect '.' to be part of dir listing x-ref: "mod_webdav readdir POSIX compatibility issue" https://redmine.lighttpd.net/issues/1826 --- NEWS | 1 + src/mod_webdav.c | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index c169e764..ea1dc834 100644 --- a/NEWS +++ b/NEWS @@ -67,6 +67,7 @@ NEWS * [mod_auth] send charset="UTF-8" in WWW-Authenticate (fixes #1468) * [mod_magnet] rename var for clarity (fixes #1483) * [mod_extforward] reset cond_cache for scheme (fixes #1499) + * [mod_webdav] readdir POSIX compat (fixes #1826) - 1.4.39 - 2016-01-02 * [core] fix memset_s call (fixes #2698) diff --git a/src/mod_webdav.c b/src/mod_webdav.c index f9655ff0..5e5dcaaf 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -1348,9 +1348,8 @@ URIHANDLER_FUNC(mod_webdav_subrequest_handler) { prop_200 = buffer_init(); prop_404 = buffer_init(); - switch(depth) { - case 0: - /* Depth: 0 */ + { + /* Depth: 0 or Depth: 1 */ webdav_get_props(srv, con, p, &(con->physical), req_props, prop_200, prop_404); buffer_append_string_len(b,CONST_STR_LEN("\n")); @@ -1387,9 +1386,10 @@ URIHANDLER_FUNC(mod_webdav_subrequest_handler) { } buffer_append_string_len(b,CONST_STR_LEN("\n")); + } + + if (depth == 1) { - break; - case 1: if (NULL != (dir = opendir(con->physical.path->ptr))) { struct dirent *de; physical d; @@ -1399,9 +1399,9 @@ URIHANDLER_FUNC(mod_webdav_subrequest_handler) { d.rel_path = buffer_init(); while(NULL != (de = readdir(dir))) { - if (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0') { + if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { continue; - /* ignore the parent dir */ + /* ignore the parent and target dir */ } buffer_copy_buffer(d.path, dst->path); @@ -1410,12 +1410,8 @@ URIHANDLER_FUNC(mod_webdav_subrequest_handler) { buffer_copy_buffer(d.rel_path, dst->rel_path); buffer_append_slash(d.rel_path); - if (de->d_name[0] == '.' && de->d_name[1] == '\0') { - /* don't append the . */ - } else { - buffer_append_string(d.path, de->d_name); - buffer_append_string(d.rel_path, de->d_name); - } + buffer_append_string(d.path, de->d_name); + buffer_append_string(d.rel_path, de->d_name); buffer_reset(prop_200); buffer_reset(prop_404); @@ -1461,7 +1457,7 @@ URIHANDLER_FUNC(mod_webdav_subrequest_handler) { buffer_free(d.path); buffer_free(d.rel_path); } - break; + } if (req_props) { -- 2.11.4.GIT