From 354439f004af51c3b09966283ea484f107a81134 Mon Sep 17 00:00:00 2001 From: Ben Reser Date: Thu, 31 Oct 2013 00:44:20 +0000 Subject: [PATCH] mod_dav_svn: Fix crashes with other modules that don't expect r->filename to be NULL (e.g. mod_wsgi). * subversion/mod_dav_svn/mod_dav_svn.c (dav_svn__translate_name): Calculate a bogus path to put in r->filename of the form "svn:/path/to/repo/path/in/repo". git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1537360 13f79535-47bb-0310-9956-ffa450edef68 --- subversion/mod_dav_svn/mod_dav_svn.c | 50 +++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/subversion/mod_dav_svn/mod_dav_svn.c b/subversion/mod_dav_svn/mod_dav_svn.c index a268bcf2bbe7f..d9a6adc3bd358 100644 --- a/subversion/mod_dav_svn/mod_dav_svn.c +++ b/subversion/mod_dav_svn/mod_dav_svn.c @@ -1095,30 +1095,62 @@ static int dav_svn__handler(request_rec *r) #define NO_MAP_TO_STORAGE_NOTE "dav_svn-no-map-to-storage" -/* Prevent filename on the request from being set since we aren't serving a - * file off the disk. This means that blocks will not match and - * that * %f in logging formats will show as "-". */ +/* Fill the filename on the request with a bogus path since we aren't serving + * a file off the disk. This means that blocks will not match and + * that %f in logging formats will show as "svn:/path/to/repo/path/in/repo". */ static int dav_svn__translate_name(request_rec *r) { + const char *fs_path, *repos_basename, *repos_path; + const char *ignore_cleaned_uri, *ignore_relative_path; + int ignore_had_slash; + dav_error *err; dir_conf_t *conf = ap_get_module_config(r->per_dir_config, &dav_svn_module); /* module is not configured, bail out early */ if (!conf->fs_path && !conf->fs_parent_path) return DECLINED; - /* Be paranoid and set it to NULL just in case some other module set it - * before we got called. */ - r->filename = NULL; + /* Retrieve path to repo and within repo for the request */ + if ((err = dav_svn_split_uri(r, r->uri, conf->root_dir, &ignore_cleaned_uri, + &ignore_had_slash, &repos_basename, + &ignore_relative_path, &repos_path))) + { + dav_svn__log_err(r, err, APLOG_ERR); + return HTTP_INTERNAL_SERVER_ERROR; + } + if (conf->fs_parent_path) + { + fs_path = svn_dirent_join(conf->fs_parent_path, repos_basename, + r->pool); + } + else + { + fs_path = conf->fs_path; + } - /* Leave a note to ourselves so that we know not to decline in the + /* Before we can combine repos_path with fs_path need to make sure it isn't + * NULL and to skip the leading '/' to "convert" it to a relpath appropriate + * for joining. */ + if (!repos_path) + repos_path = ""; + else if ('/' == *repos_path) + repos_path++; + + /* Combine 'svn:', fs_path and repos_path to produce the bogus path we're + * placing in r->filename. */ + r->filename = apr_pstrcat(r->pool, "svn:", + svn_dirent_join(fs_path, repos_path, r->pool), + NULL); + + /* Leave a note to ourselves so that we know not to decline in the * map_to_storage hook. */ - apr_table_setn(r->notes, NO_MAP_TO_STORAGE_NOTE, (const char*)1); + apr_table_setn(r->notes, NO_MAP_TO_STORAGE_NOTE, (const char*)1); return OK; } /* Prevent core_map_to_storage from running if we prevented the r->filename * from being set since core_map_to_storage doesn't like r->filename being - * NULL. */ + * bogus. */ static int dav_svn__map_to_storage(request_rec *r) { /* Check a note we left in translate_name since map_to_storage doesn't