From a3a951a57625b39c7bba1b6c4b34141a033e26b1 Mon Sep 17 00:00:00 2001 From: Greg Stein Date: Thu, 24 Jan 2002 23:11:27 +0000 Subject: [PATCH] Some extra tweaks to the DAV code file/path handling (to continue the platforms fixes done by wrowe). * dav_fs_get_parent_resource(): return NULL if we're at the root of the URL (Location) space. * dav_fs_dir_file_name(): make it return an error, in case we're passed a bad path. adjusted callers [who just ignore it for now] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93009 13f79535-47bb-0310-9956-ffa450edef68 --- modules/dav/fs/dbm.c | 3 ++- modules/dav/fs/lock.c | 6 ++++-- modules/dav/fs/repos.c | 23 +++++++++++++++++------ modules/dav/fs/repos.h | 6 +++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/modules/dav/fs/dbm.c b/modules/dav/fs/dbm.c index b2b1e8cc23..c4db7c453b 100644 --- a/modules/dav/fs/dbm.c +++ b/modules/dav/fs/dbm.c @@ -197,7 +197,8 @@ static dav_error * dav_dbm_open(apr_pool_t * p, const dav_resource *resource, const char *pathname; /* Get directory and filename for resource */ - dav_fs_dir_file_name(resource, &dirpath, &fname); + /* ### should test this result value... */ + (void) dav_fs_dir_file_name(resource, &dirpath, &fname); /* If not opening read-only, ensure the state dir exists */ if (!ro) { diff --git a/modules/dav/fs/lock.c b/modules/dav/fs/lock.c index bfc37c2831..1d1c88c7b4 100644 --- a/modules/dav/fs/lock.c +++ b/modules/dav/fs/lock.c @@ -992,7 +992,8 @@ dav_error * dav_fs_get_locknull_members( { const char *dirpath; - dav_fs_dir_file_name(resource, &dirpath, NULL); + /* ### should test this result value... */ + (void) dav_fs_dir_file_name(resource, &dirpath, NULL); return dav_fs_load_locknull_list(dav_fs_pool(resource), dirpath, pbuf); } @@ -1008,7 +1009,8 @@ static dav_error * dav_fs_add_locknull_state( const char *fname; dav_error *err; - dav_fs_dir_file_name(resource, &dirpath, &fname); + /* ### should test this result value... */ + (void) dav_fs_dir_file_name(resource, &dirpath, &fname); if ((err = dav_fs_load_locknull_list(p, dirpath, &buf)) != NULL) { return dav_push_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index 9b75d9fb3f..29203d4ffe 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -235,7 +235,7 @@ const char *dav_fs_pathname(const dav_resource *resource) return resource->info->pathname; } -void dav_fs_dir_file_name( +dav_error * dav_fs_dir_file_name( const dav_resource *resource, const char **dirpath_p, const char **fname_p) @@ -283,10 +283,13 @@ void dav_fs_dir_file_name( *fname_p = ctx->pathname + dirlen; } else { - if (fname_p != NULL) - *fname_p = NULL; + return dav_new_error(ctx->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + "An incomplete/bad path was found in " + "dav_fs_dir_file_name."); } } + + return NULL; } /* Note: picked up from ap_gm_timestr_822() */ @@ -530,8 +533,9 @@ static dav_error *dav_fs_copymoveset(int is_move, apr_pool_t *p, dav_error *err; /* Get directory and filename for resources */ - dav_fs_dir_file_name(src, &src_dir, &src_file); - dav_fs_dir_file_name(dst, &dst_dir, &dst_file); + /* ### should test these result values... */ + (void) dav_fs_dir_file_name(src, &src_dir, &src_file); + (void) dav_fs_dir_file_name(dst, &dst_dir, &dst_file); /* Get the corresponding state files for each resource */ dav_dbm_get_statefiles(p, src_file, &src_state1, &src_state2); @@ -582,7 +586,8 @@ static dav_error *dav_fs_deleteset(apr_pool_t *p, const dav_resource *resource) apr_status_t status; /* Get directory, filename, and state-file names for the resource */ - dav_fs_dir_file_name(resource, &dirpath, &fname); + /* ### should test this result value... */ + (void) dav_fs_dir_file_name(resource, &dirpath, &fname); dav_dbm_get_statefiles(p, fname, &state1, &state2); /* build the propset pathname for the file */ @@ -742,6 +747,12 @@ static dav_error * dav_fs_get_parent_resource(const dav_resource *resource, const char *testroot; const char *testpath; + /* If we're at the root of the URL space, then there is no parent. */ + if (strcmp(resource->uri, "/") == 0) { + *result_parent = NULL; + return NULL; + } + /* If given resource is root, then there is no parent. * Unless we can retrieve the filepath root, this is * intendend to fail. If we split the root and diff --git a/modules/dav/fs/repos.h b/modules/dav/fs/repos.h index 828b17a973..0f283fb010 100644 --- a/modules/dav/fs/repos.h +++ b/modules/dav/fs/repos.h @@ -75,9 +75,9 @@ apr_pool_t *dav_fs_pool(const dav_resource *resource); const char *dav_fs_pathname(const dav_resource *resource); /* return the directory and filename for a resource */ -void dav_fs_dir_file_name(const dav_resource *resource, - const char **dirpath, - const char **fname); +dav_error * dav_fs_dir_file_name(const dav_resource *resource, + const char **dirpath, + const char **fname); /* return the list of locknull members in this resource's directory */ dav_error * dav_fs_get_locknull_members(const dav_resource *resource, -- 2.40.0