]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
merge this from 2.1-dev:
authorJeff Trawick <trawick@apache.org>
Wed, 17 Sep 2003 10:30:47 +0000 (10:30 +0000)
committerJeff Trawick <trawick@apache.org>
Wed, 17 Sep 2003 10:30:47 +0000 (10:30 +0000)
    * Avoid an infinite recursion, which occured if the name of an included
      config file or directory contained a wildcard character. PR 22194.
      (2.0 + 1.3)

PR:              22194
Submitted by:  Andr�� Malo
Reviewed by:  trawick, fielding

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/APACHE_2_0_BRANCH@101263 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
server/config.c

diff --git a/CHANGES b/CHANGES
index 7f26896032ec250ac1fa67c3387a334caa0451e0..7a9e6c87e0661fe0913b6524c09ea3d708b20210 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,9 @@
 Changes with Apache 2.0.48
 
+  *) Avoid an infinite recursion, which occured if the name of an included
+     config file or directory contained a wildcard character. PR 22194.
+     [André Malo]
+
   *) mod_ssl: Fix a problem setting variables that represent the
      client certificate chain.  PR 21371  [Jeff Trawick]
 
diff --git a/STATUS b/STATUS
index 40244729b6177b199ea0a1010b3280dc06411a30..ea7b2435d513a929845a68cbb6f3317b30a7b283 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -1,5 +1,5 @@
 APACHE 2.0 STATUS:                                              -*-text-*-
-Last modified at [$Date: 2003/09/17 01:51:55 $]
+Last modified at [$Date: 2003/09/17 10:30:46 $]
 
 Release:
 
@@ -277,12 +277,6 @@ PATCHES TO PORT FROM 2.1
       +1: nd, trawick
       (gstein likes the concept, but needs to review...)
 
-    * Avoid an infinite recursion, which occured if the name of an included
-      config file or directory contained a wildcard character. PR 22194.
-      (2.0 + 1.3)
-        server/config.c: r1.165
-      +1: nd, trawick, fielding
-
     * mod_ssl: fix a link failure when the openssl-engine libraries are
       present but the engine headers are missing.
         modules/ssl/mod_ssl.c: r1.87
index 68ff4f219e2a8bbc0b79238fdc9294d8114218ac..a8e803a85584d3ddcdb729477dd45778635d9ca1 100644 (file)
@@ -1442,64 +1442,23 @@ static int fname_alphasort(const void *fn1, const void *fn2)
     return strcmp(f1->fname,f2->fname);
 }
 
-AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname,
-                                            ap_directive_t **conftree,
-                                            apr_pool_t *p,
-                                            apr_pool_t *ptemp)
+static void process_resource_config_nofnmatch(server_rec *s, const char *fname,
+                                              ap_directive_t **conftree,
+                                              apr_pool_t *p,
+                                              apr_pool_t *ptemp)
 {
     cmd_parms parms;
-    apr_finfo_t finfo;
-    const char *errmsg;
     ap_configfile_t *cfp;
-    int ispatt;
-
-    /* XXX: lstat() won't work on the wildcard pattern...
-     */
-
-    /* don't require conf/httpd.conf if we have a -C or -c switch */
-    if ((ap_server_pre_read_config->nelts
-        || ap_server_post_read_config->nelts)
-        && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
-        if (apr_lstat(&finfo, fname, APR_FINFO_TYPE, p) != APR_SUCCESS)
-            return;
-    }
+    const char *errmsg;
 
-    ispatt = apr_fnmatch_test(fname);
-    if (ispatt || ap_is_rdirectory(p, fname)) {
+    if (ap_is_rdirectory(p, fname)) {
         apr_dir_t *dirp;
         apr_finfo_t dirent;
         int current;
         apr_array_header_t *candidates = NULL;
         fnames *fnew;
         apr_status_t rv;
-        char errmsg[120], *path = apr_pstrdup(p, fname), *pattern = NULL;
-
-        if (ispatt) {
-            pattern = ap_strrchr(path, '/');
-        
-            AP_DEBUG_ASSERT(pattern != NULL); /* path must be absolute. */
-        
-            *pattern++ = '\0';
-            
-            if (apr_fnmatch_test(path)) {
-                fprintf(stderr, "%s: wildcard patterns not allowed in Include "
-                        "%s\n", ap_server_argv0, fname);
-                exit(1);
-            }
-
-            if (!ap_is_rdirectory(p, path)){ 
-                fprintf(stderr, "%s: Include directory '%s' not found",
-                        ap_server_argv0, path);
-                exit(1);
-            }
-            
-            if (!apr_fnmatch_test(pattern)) {
-                fprintf(stderr, "%s: must include a wildcard pattern "
-                        "for Include %s\n", ap_server_argv0, fname);
-                exit(1);
-            }
-
-        }
+        char errmsg[120], *path = apr_pstrdup(p, fname);
 
         /*
          * first course of business is to grok all the directory
@@ -1518,10 +1477,7 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname,
         while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
             /* strip out '.' and '..' */
             if (strcmp(dirent.name, ".")
-                && strcmp(dirent.name, "..")
-                && (!ispatt ||
-                    apr_fnmatch(pattern, dirent.name, 
-                                FNM_PERIOD) == APR_SUCCESS)) {
+                && strcmp(dirent.name, "..")) {
                 fnew = (fnames *) apr_array_push(candidates);
                 fnew->fname = ap_make_full_path(p, path, dirent.name);
             }
@@ -1538,7 +1494,8 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname,
              */
             for (current = 0; current < candidates->nelts; ++current) {
                 fnew = &((fnames *) candidates->elts)[current];
-                ap_process_resource_config(s, fnew->fname, conftree, p, ptemp);
+                process_resource_config_nofnmatch(s, fnew->fname, conftree, p,
+                                                  ptemp);
             }
         }
 
@@ -1546,7 +1503,6 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname,
     }
 
     /* GCC's initialization extensions are soooo nice here... */
-
     parms = default_parms;
     parms.pool = p;
     parms.temp_pool = ptemp;
@@ -1575,6 +1531,107 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname,
     }
 
     ap_cfg_closefile(cfp);
+
+    return;
+}
+
+AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname,
+                                            ap_directive_t **conftree,
+                                            apr_pool_t *p,
+                                            apr_pool_t *ptemp)
+{
+    /* XXX: lstat() won't work on the wildcard pattern...
+     */
+
+    /* don't require conf/httpd.conf if we have a -C or -c switch */
+    if ((ap_server_pre_read_config->nelts
+        || ap_server_post_read_config->nelts)
+        && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
+        apr_finfo_t finfo;
+
+        if (apr_lstat(&finfo, fname, APR_FINFO_TYPE, p) != APR_SUCCESS)
+            return;
+    }
+
+    if (!apr_fnmatch_test(fname)) {
+        process_resource_config_nofnmatch(s, fname, conftree, p, ptemp);
+    }
+    else {
+        apr_dir_t *dirp;
+        apr_finfo_t dirent;
+        int current;
+        apr_array_header_t *candidates = NULL;
+        fnames *fnew;
+        apr_status_t rv;
+        char errmsg[120], *path = apr_pstrdup(p, fname), *pattern = NULL;
+
+        pattern = ap_strrchr(path, '/');
+
+        AP_DEBUG_ASSERT(pattern != NULL); /* path must be absolute. */
+
+        *pattern++ = '\0';
+
+        if (apr_fnmatch_test(path)) {
+            fprintf(stderr, "%s: wildcard patterns not allowed in Include "
+                    "%s\n", ap_server_argv0, fname);
+            exit(1);
+        }
+
+        if (!ap_is_rdirectory(p, path)){ 
+            fprintf(stderr, "%s: Include directory '%s' not found",
+                    ap_server_argv0, path);
+            exit(1);
+        }
+
+        if (!apr_fnmatch_test(pattern)) {
+            fprintf(stderr, "%s: must include a wildcard pattern "
+                    "for Include %s\n", ap_server_argv0, fname);
+            exit(1);
+        }
+
+        /*
+         * first course of business is to grok all the directory
+         * entries here and store 'em away. Recall we need full pathnames
+         * for this.
+         */
+        rv = apr_dir_open(&dirp, path, p);
+        if (rv != APR_SUCCESS) {
+            fprintf(stderr, "%s: could not open config directory %s: %s\n",
+                    ap_server_argv0, path,
+                    apr_strerror(rv, errmsg, sizeof errmsg));
+            exit(1);
+        }
+
+        candidates = apr_array_make(p, 1, sizeof(fnames));
+        while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
+            /* strip out '.' and '..' */
+            if (strcmp(dirent.name, ".")
+                && strcmp(dirent.name, "..")
+                && (apr_fnmatch(pattern, dirent.name,
+                                FNM_PERIOD) == APR_SUCCESS)) {
+                fnew = (fnames *) apr_array_push(candidates);
+                fnew->fname = ap_make_full_path(p, path, dirent.name);
+            }
+        }
+
+        apr_dir_close(dirp);
+        if (candidates->nelts != 0) {
+            qsort((void *) candidates->elts, candidates->nelts,
+                  sizeof(fnames), fname_alphasort);
+
+            /*
+             * Now recurse these... we handle errors and subdirectories
+             * via the recursion, which is nice
+             */
+            for (current = 0; current < candidates->nelts; ++current) {
+                fnew = &((fnames *) candidates->elts)[current];
+                process_resource_config_nofnmatch(s, fnew->fname, conftree, p,
+                                                  ptemp);
+            }
+        }
+    }
+
+    return;
 }
 
 AP_DECLARE(void) ap_process_config_tree(server_rec *s,