From 8ee1c0a5d794bed55fe0bc99fc4cbb26567f9ead Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Tue, 25 Dec 2012 20:43:15 +0000 Subject: [PATCH] Replace strdup by ap_malloc to ensure a proper error message if out-of-memory. 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/config.c b/server/config.c index 0483ce20cb..733d9c285f 100644 --- a/server/config.c +++ b/server/config.c @@ -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*/ -- 2.49.0