]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Don't use NULL s->server_hostname as hash lookup key.
authorNick Kew <niq@apache.org>
Fri, 18 Aug 2006 12:16:13 +0000 (12:16 +0000)
committerNick Kew <niq@apache.org>
Fri, 18 Aug 2006 12:16:13 +0000 (12:16 +0000)
Reported by paritosh (at limewire.co.in) on dev@httpd (thread
Re: apache 2.2 crashes at the start time in mod_dbd.c then preparing AuthDBDUserPWQuery)
Fixed by paritosh and Yours Truly.

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

modules/database/mod_dbd.c

index c236fedd86867a0f383645d57fc6a9a844119435..76eeca2b4c729dd37db6074b72666017e8d2019b 100644 (file)
@@ -68,6 +68,7 @@ typedef enum { cmd_name, cmd_params, cmd_persist,
 } cmd_parts;
 
 static apr_hash_t *dbd_prepared_defns;
+static const char *const default_hostname = "*";
 
 /* a default DBDriver value that'll generate meaningful error messages */
 static const char *const no_dbdriver = "[DBDriver unset]";
@@ -147,12 +148,14 @@ DBD_DECLARE_NONSTD(void) ap_dbd_prepare(server_rec *s, const char *query,
                                         const char *label)
 {
     dbd_prepared *prepared = apr_pcalloc(s->process->pool, sizeof(dbd_prepared));
+    const char *key = s->server_hostname;
+    if (key == NULL) {
+        key = default_hostname;
+    }
     prepared->label = label;
     prepared->query = query;
-    prepared->next = apr_hash_get(dbd_prepared_defns, s->server_hostname,
-                                  APR_HASH_KEY_STRING);
-    apr_hash_set(dbd_prepared_defns, s->server_hostname, APR_HASH_KEY_STRING,
-                 prepared);
+    prepared->next = apr_hash_get(dbd_prepared_defns, key, APR_HASH_KEY_STRING);
+    apr_hash_set(dbd_prepared_defns, key, APR_HASH_KEY_STRING, prepared);
 }
 static const char *dbd_prepare(cmd_parms *cmd, void *cfg, const char *query,
                                const char *label)
@@ -618,8 +621,12 @@ static int dbd_post_config(apr_pool_t *pconf, apr_pool_t *plog,
     svr_cfg *svr;
     server_rec *sp;
     for (sp = s; sp; sp = sp->next) {
+        const char *key = s->server_hostname;
+        if (key == NULL) {
+            key = default_hostname;
+        }
         svr = ap_get_module_config(sp->module_config, &dbd_module);
-        svr->prepared = apr_hash_get(dbd_prepared_defns, sp->server_hostname,
+        svr->prepared = apr_hash_get(dbd_prepared_defns, key,
                                      APR_HASH_KEY_STRING);
     }
     return OK;