From: André Malo Date: Mon, 24 Feb 2003 21:44:15 +0000 (+0000) Subject: This is part two. X-Git-Tag: pre_ajp_proxy~2083 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c89fed043c0765a0a206a8ee3d0c0bf2f8504bd;p=apache This is part two. It fixes the prefix_stat function. (which does a stat call on the first path segment). This function was still tailored for unix systems only. It should work on other systems as well now. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@98782 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 75e17a1010..84e20714bc 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -1083,7 +1083,6 @@ static int hook_uri2file(request_rec *r) char docroot[512]; char *cp, *cp2; const char *ccp; - apr_finfo_t finfo; unsigned int port; int rulestatus; int n; @@ -1313,7 +1312,7 @@ static int hook_uri2file(request_rec *r) * because we only do stat() on the first directory * and this gets cached by the kernel for along time! */ - n = prefix_stat(r->filename, &finfo); + n = prefix_stat(r->filename, r->pool); if (n == 0) { if ((ccp = ap_document_root(r)) != NULL) { l = apr_cpystrn(docroot, ccp, sizeof(docroot)) - docroot; @@ -4219,24 +4218,45 @@ static int subreq_ok(request_rec *r) ** */ -static int prefix_stat(const char *path, apr_finfo_t *sb) +static int prefix_stat(const char *path, apr_pool_t *pool) { - char curpath[LONG_STRING_LEN]; - char *cp; + const char *curpath = path; + char *root; + char *slash; + char *statpath; + apr_status_t rv; - apr_cpystrn(curpath, path, sizeof(curpath)); - if (curpath[0] != '/') { + rv = apr_filepath_root(&root, &curpath, APR_FILEPATH_TRUENAME, pool); + + if (rv != APR_SUCCESS) { return 0; } - if ((cp = strchr(curpath+1, '/')) != NULL) { - *cp = '\0'; - } - if (apr_stat(sb, curpath, APR_FINFO_MIN, NULL) == APR_SUCCESS) { - return 1; + + /* let's recognize slashes only, the mod_rewrite semantics are opaque + * enough. + */ + if ((slash = ap_strchr(curpath, '/')) != NULL) { + rv = apr_filepath_merge(&statpath, root, + apr_pstrndup(pool, curpath, + (apr_size_t)(slash - curpath)), + APR_FILEPATH_NOTABOVEROOT | + APR_FILEPATH_NOTRELATIVE, pool); } else { - return 0; + rv = apr_filepath_merge(&statpath, root, curpath, + APR_FILEPATH_NOTABOVEROOT | + APR_FILEPATH_NOTRELATIVE, pool); } + + if (rv == APR_SUCCESS) { + apr_finfo_t sb; + + if (apr_stat(&sb, statpath, APR_FINFO_MIN, pool) == APR_SUCCESS) { + return 1; + } + } + + return 0; } diff --git a/modules/mappers/mod_rewrite.h b/modules/mappers/mod_rewrite.h index 08824eb5a4..c826359b41 100644 --- a/modules/mappers/mod_rewrite.h +++ b/modules/mappers/mod_rewrite.h @@ -462,7 +462,7 @@ static void store_cache_string(cache *c, const char *res, cacheentry *ce); static char *subst_prefix_path(request_rec *r, char *input, char *match, const char *subst); static int parseargline(char *str, char **a1, char **a2, char **a3); -static int prefix_stat(const char *path, apr_finfo_t *sb); +static int prefix_stat(const char *path, apr_pool_t *pool); static void add_env_variable(request_rec *r, char *s); static void add_cookie(request_rec *r, char *s); static int subreq_ok(request_rec *r);