]> granicus.if.org Git - apache/commitdiff
Replace strdup by ap_malloc to ensure a proper error message if out-of-memory.
authorStefan Fritsch <sf@apache.org>
Tue, 25 Dec 2012 20:43:15 +0000 (20:43 +0000)
committerStefan Fritsch <sf@apache.org>
Tue, 25 Dec 2012 20:43:15 +0000 (20:43 +0000)
While there, only allocate memory for the string part we actually use.

PR: 54345

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

server/config.c

index 0483ce20cb19fd400aee94ac7c915f02a87d95f6..733d9c285fa9514b16940b70eb6c8183995d2738 100644 (file)
@@ -603,7 +603,8 @@ AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p,
             len -= slen;
         }
 
-        ap_module_short_names[m->module_index] = strdup(sym_name);
+        ap_module_short_names[m->module_index] = ap_malloc(len + 1);
+        memcpy(ap_module_short_names[m->module_index], sym_name, len);
         ap_module_short_names[m->module_index][len] = '\0';
         merger_func_cache[m->module_index] = m->merge_dir_config;
     }
@@ -627,8 +628,9 @@ AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p,
 
     /* We cannot fix the string in-place, because it's const */
     if (m->name[strlen(m->name)-1] == ')') {
-        char *tmp = strdup(m->name); /* FIXME: memory leak, albeit a small one */
-        tmp[strlen(tmp)-1] = '\0';
+        char *tmp = ap_malloc(strlen(m->name)); /* FIXME: memory leak, albeit a small one */
+        memcpy(tmp, m->name, strlen(m->name)-1);
+        tmp[strlen(m->name)-1] = '\0';
         m->name = tmp;
     }
 #endif /*_OSD_POSIX*/