From 09f0d64d33d12ece33c2e08359517fb318bf0d23 Mon Sep 17 00:00:00 2001 From: Greg Stein Date: Wed, 29 Nov 2000 17:33:03 +0000 Subject: [PATCH] Use "const char * const *" for process->argv (which is the correct const-ness since we sometimes put "some string" in there, and also the CRT's argv). propagate this change within http_main and mpm/winnt/ (also correct some other const type usage within the MPM). fix ab's call to parse_url() which removed a const to actually manipulate an arg from the CRT's argv (indirectly via opt->arg). no idea how this has avoided segfaulting. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87130 13f79535-47bb-0310-9956-ffa450edef68 --- include/httpd.h | 2 +- server/main.c | 34 ++++++++++----------- server/mpm/winnt/mpm_winnt.c | 33 ++++++++++---------- server/mpm/winnt/registry.c | 4 ++- server/mpm/winnt/service.c | 59 +++++++++++++++++++----------------- support/ab.c | 6 ++-- 6 files changed, 71 insertions(+), 67 deletions(-) diff --git a/include/httpd.h b/include/httpd.h index 13eed4b069..049e454a37 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -597,7 +597,7 @@ struct process_rec { /** How many command line arguments were pass to the program */ int argc; /** The command line arguments */ - char *const *argv; + const char * const *argv; /** The program name used to execute the program */ const char *short_name; }; diff --git a/server/main.c b/server/main.c index 57cf359062..4bd5de728b 100644 --- a/server/main.c +++ b/server/main.c @@ -203,26 +203,24 @@ static void destroy_and_exit_process(process_rec *process, int process_exit_valu exit(process_exit_value); } -static process_rec *create_process(int argc, char *const *argv) +static process_rec *create_process(int argc, const char * const *argv) { process_rec *process; - - { - apr_pool_t *cntx; - apr_status_t stat; - - stat = apr_create_pool(&cntx, NULL); - if (stat != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL, - "apr_create_pool() failed to create " - "initial context"); - apr_terminate(); - exit(1); - } - - process = apr_palloc(cntx, sizeof(process_rec)); - process->pool = cntx; + apr_pool_t *cntx; + apr_status_t stat; + + stat = apr_create_pool(&cntx, NULL); + if (stat != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL, + "apr_create_pool() failed to create " + "initial context"); + apr_terminate(); + exit(1); } + + process = apr_palloc(cntx, sizeof(process_rec)); + process->pool = cntx; + apr_create_pool(&process->pconf, process->pool); process->argc = argc; process->argv = argv; @@ -281,7 +279,7 @@ static void usage(process_rec *process) destroy_and_exit_process(process, 1); } -int main(int argc, char *argv[]) +int main(int argc, const char * const argv[]) { char c; int configtestonly = 0; diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 16aafee944..e10af947d2 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -1789,7 +1789,7 @@ die_now: } -#define SERVICE_UNNAMED -1 +#define SERVICE_UNNAMED (-1) /* service_nt_main_fn needs to append the StartService() args * outside of our call stack and thread as the service starts... @@ -1803,7 +1803,7 @@ apr_array_header_t *mpm_new_argv; static apr_status_t service_to_start_success; static int inst_argc; -static char **inst_argv; +static const char * const *inst_argv; void winnt_rewrite_args(process_rec *process) { @@ -1887,18 +1887,16 @@ void winnt_rewrite_args(process_rec *process) * initial pre-flight of the config parser. */ - mpm_new_argv = apr_make_array(process->pool, process->argc + 2, sizeof(char *)); - new_arg = (char**) apr_push_array(mpm_new_argv); - *new_arg = (char *) process->argv[0]; - - new_arg = (char**) apr_push_array(mpm_new_argv); - *new_arg = "-d"; - new_arg = (char**) apr_push_array(mpm_new_argv); - *new_arg = def_server_root; + mpm_new_argv = apr_make_array(process->pool, process->argc + 2, + sizeof(const char *)); + *(const char **)apr_push_array(mpm_new_argv) = process->argv[0]; + *(const char **)apr_push_array(mpm_new_argv) = "-d"; + *(const char **)apr_push_array(mpm_new_argv) = def_server_root; fixed_args = mpm_new_argv->nelts; - optbuf[0] = '-'; optbuf[2] = '\0'; + optbuf[0] = '-'; + optbuf[2] = '\0'; apr_initopt(&opt, process->pool, process->argc, (char**) process->argv); while (apr_getopt(opt, "n:k:iu" AP_SERVER_BASEARGS, optbuf + 1, &optarg) == APR_SUCCESS) { @@ -1920,11 +1918,11 @@ void winnt_rewrite_args(process_rec *process) signal_arg = "uninstall"; break; default: - new_arg = (char**) apr_push_array(mpm_new_argv); - *new_arg = apr_pstrdup(process->pool, optbuf); + *(const char **)apr_push_array(mpm_new_argv) = + apr_pstrdup(process->pool, optbuf); + if (optarg) { - new_arg = (char**) apr_push_array(mpm_new_argv); - *new_arg = optarg; + *(const char **)apr_push_array(mpm_new_argv) = optarg; } break; } @@ -2005,10 +2003,11 @@ void winnt_rewrite_args(process_rec *process) * These will be used for the -k install parameters, as well as * for the -k start service override arguments. */ - inst_argv = (char**) mpm_new_argv->elts + mpm_new_argv->nelts - inst_argc; + inst_argv = (const char * const *)mpm_new_argv->elts + + mpm_new_argv->nelts - inst_argc; process->argc = mpm_new_argv->nelts; - process->argv = (char**) mpm_new_argv->elts; + process->argv = (const char * const *) mpm_new_argv->elts; } diff --git a/server/mpm/winnt/registry.c b/server/mpm/winnt/registry.c index 4b30b3ddb0..e312285ae3 100644 --- a/server/mpm/winnt/registry.c +++ b/server/mpm/winnt/registry.c @@ -358,7 +358,9 @@ apr_status_t ap_registry_store_value(const char *key, const char *name, const ch return_error(rv); } -apr_status_t ap_registry_store_array(apr_pool_t *p, const char *key, const char *name, int nelts, char const* const* elts) +apr_status_t ap_registry_store_array(apr_pool_t *p, + const char *key, const char *name, + int nelts, const char * const * elts) { int bufsize, i; char *buf, *tmp; diff --git a/server/mpm/winnt/service.c b/server/mpm/winnt/service.c index b02b2d98ce..4f8d190fb2 100644 --- a/server/mpm/winnt/service.c +++ b/server/mpm/winnt/service.c @@ -88,10 +88,11 @@ #include "mpm_winnt.h" #include "apr_strings.h" -char const* service_name = NULL; -char const* display_name = NULL; -char const* signal_arg = NULL; - +static const char * service_name = NULL; + +/* ### should be namespace-protected */ +const char * display_name = NULL; + static struct { HANDLE mpm_thread; /* primary thread handle of the apache server */ @@ -536,7 +537,7 @@ static void __stdcall service_nt_main_fn(DWORD argc, LPTSTR *argv) globdat.ssStatus.dwServiceSpecificExitCode = 0; globdat.ssStatus.dwCheckPoint = 1; - if(!(globdat.hServiceStatus = RegisterServiceCtrlHandler(argv[0], service_nt_ctrl))) + if (!(globdat.hServiceStatus = RegisterServiceCtrlHandler(argv[0], service_nt_ctrl))) { ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(), NULL, "Failure registering service handler"); @@ -594,9 +595,11 @@ static void __stdcall service_nt_main_fn(DWORD argc, LPTSTR *argv) */ if (argc > 1) { - char **cmb_data; - cmb_data = apr_palloc(mpm_new_argv->cont, - (mpm_new_argv->nelts + argc - 1) * sizeof(char *)); + const char **cmb_data; + + mpm_new_argv->nalloc = mpm_new_argv->nelts + argc - 1; + cmb_data = apr_palloc(mpm_new_argv->cont, + mpm_new_argv->nalloc * sizeof(const char *)); /* mpm_new_argv remains first (of lower significance) */ memcpy (cmb_data, mpm_new_argv->elts, @@ -607,8 +610,8 @@ static void __stdcall service_nt_main_fn(DWORD argc, LPTSTR *argv) mpm_new_argv->elt_size * (argc - 1)); /* The replacement arg list is complete */ - mpm_new_argv->elts = (char*) cmb_data; - mpm_new_argv->nalloc = mpm_new_argv->nelts += argc - 1; + mpm_new_argv->elts = (char *)cmb_data; + mpm_new_argv->nelts = mpm_new_argv->nalloc; } /* Let the main thread continue now... but hang on to the @@ -670,7 +673,7 @@ apr_status_t mpm_merge_service_args(apr_pool_t *p, { apr_array_header_t *svc_args = NULL; char conf_key[MAX_PATH]; - char **cmb_data; + const char **cmb_data; apr_status_t rv; apr_snprintf(conf_key, sizeof(conf_key), SERVICEPARAMS, service_name); @@ -696,22 +699,23 @@ apr_status_t mpm_merge_service_args(apr_pool_t *p, * time to _prepend_ the default arguments for the server from * the service's default arguments (all others override them)... */ - cmb_data = apr_palloc(p, (args->nelts + svc_args->nelts) * sizeof(char *)); + args->nalloc = args->nelts + svc_args->nelts; + cmb_data = apr_palloc(p, args->nalloc * sizeof(const char *)); /* First three args (argv[0], -f, path) remain first */ - memcpy (cmb_data, args->elts, args->elt_size * fixed_args); + memcpy(cmb_data, args->elts, args->elt_size * fixed_args); /* Service args follow from service registry array */ - memcpy (cmb_data + fixed_args, svc_args->elts, - svc_args->elt_size * svc_args->nelts); + memcpy(cmb_data + fixed_args, svc_args->elts, + svc_args->elt_size * svc_args->nelts); /* Remaining new args follow */ - memcpy (cmb_data + fixed_args + svc_args->nelts, - (char**) args->elts + fixed_args, - args->elt_size * (args->nelts - fixed_args)); + memcpy(cmb_data + fixed_args + svc_args->nelts, + (const char **)args->elts + fixed_args, + args->elt_size * (args->nelts - fixed_args)); - args->elts = (char*) cmb_data; - args->nalloc = (args->nelts += svc_args->nelts); + args->elts = (char *)cmb_data; + args->nelts = args->nalloc; return APR_SUCCESS; } @@ -814,7 +818,7 @@ void mpm_service_stopping(void) apr_status_t mpm_service_install(apr_pool_t *ptemp, int argc, - char const* const* argv) + const char * const * argv) { char key_name[MAX_PATH]; char exe_path[MAX_PATH]; @@ -1020,7 +1024,7 @@ static int signal_service_transition(SC_HANDLE schService, DWORD signal, DWORD p apr_status_t mpm_service_start(apr_pool_t *ptemp, int argc, - char const* const* argv) + const char * const * argv) { apr_status_t rv; @@ -1028,7 +1032,7 @@ apr_status_t mpm_service_start(apr_pool_t *ptemp, int argc, if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT) { - char **start_argv; + const char **start_argv; SC_HANDLE schService; SC_HANDLE schSCManager; @@ -1062,10 +1066,10 @@ apr_status_t mpm_service_start(apr_pool_t *ptemp, int argc, } argc += 1; - start_argv = apr_palloc(ptemp, argc * sizeof(char**)); - start_argv[0] = (char*) service_name; + start_argv = apr_palloc(ptemp, argc * sizeof(const char **)); + start_argv[0] = service_name; if (argc > 1) - memcpy(start_argv + 1, argv, (argc - 1) * sizeof(char**)); + memcpy(start_argv + 1, argv, (argc - 1) * sizeof(const char **)); rv = APR_EINIT; if (StartService(schService, argc, start_argv) @@ -1115,7 +1119,8 @@ apr_status_t mpm_service_start(apr_pool_t *ptemp, int argc, pCommand = apr_psprintf(ptemp, "\"%s\" -n %s -k runservice", exe_path, service_name); for (i = 0; i < argc; ++i) { - pCommand = apr_pstrcat(ptemp, pCommand, " \"", argv[i], "\"", NULL); + pCommand = apr_pstrcat(ptemp, pCommand, + " \"", argv[i], "\"", NULL); } memset(&si, 0, sizeof(si)); diff --git a/support/ab.c b/support/ab.c index 115697c18a..71f4c5962a 100644 --- a/support/ab.c +++ b/support/ab.c @@ -893,14 +893,14 @@ static void test(void) static void copyright(void) { if (!use_html) { - printf("This is ApacheBench, Version %s\n", AB_VERSION " <$Revision: 1.38 $> apache-2.0"); + printf("This is ApacheBench, Version %s\n", AB_VERSION " <$Revision: 1.39 $> apache-2.0"); printf("Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n"); printf("Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/\n"); printf("\n"); } else { printf("

\n"); - printf(" This is ApacheBench, Version %s <%s> apache-2.0
\n", AB_VERSION, "$Revision: 1.38 $"); + printf(" This is ApacheBench, Version %s <%s> apache-2.0
\n", AB_VERSION, "$Revision: 1.39 $"); printf(" Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
\n"); printf(" Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/
\n"); printf("

\n

\n"); @@ -1175,7 +1175,7 @@ int main(int argc, const char * const argv[]) usage(argv[0]); } - if (parse_url((char*)opt->argv[opt->ind++])) { + if (parse_url(apr_pstrdup(cntxt, opt->argv[opt->ind++]))) { fprintf(stderr, "%s: invalid URL\n", argv[0]); usage(argv[0]); } -- 2.50.1