diff options
author | Ivan Zhakov <ivan@apache.org> | 2019-10-15 08:17:19 +0000 |
---|---|---|
committer | Ivan Zhakov <ivan@apache.org> | 2019-10-15 08:17:19 +0000 |
commit | cd40cc64f1d526f6c1659dd5777a36fd58031597 (patch) | |
tree | f64d921f74afa989b5af55f7d9b54ac971fdc894 /threadproc | |
parent | 962070b59215d49929a72bb0dce9119a15bfce6b (diff) | |
download | apr-cd40cc64f1d526f6c1659dd5777a36fd58031597.tar.gz |
Refactoring. No functional changes intended.
* threadproc/win32/proc.c
(apr_proc_create): Do not share code to build CMDLINE in different situations.
SHELLCMD, .bat and regular executables have different rules for cmdline
escaping.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1868469 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc')
-rw-r--r-- | threadproc/win32/proc.c | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/threadproc/win32/proc.c b/threadproc/win32/proc.c index 4821ea676..05953e347 100644 --- a/threadproc/win32/proc.c +++ b/threadproc/win32/proc.c @@ -488,17 +488,6 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, argv0 = progname; } - /* Handle the args, seperate from argv0 */ - cmdline = ""; - for (i = 1; args && args[i]; ++i) { - if (has_space(args[i]) || !args[i][0]) { - cmdline = apr_pstrcat(pool, cmdline, " \"", args[i], "\"", NULL); - } - else { - cmdline = apr_pstrcat(pool, cmdline, " ", args[i], NULL); - } - } - if (attr->cmdtype == APR_SHELLCMD || attr->cmdtype == APR_SHELLCMD_ENV) { char *shellcmd = getenv("COMSPEC"); if (!shellcmd) { @@ -517,6 +506,17 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, } } + /* Handle the args, separate from argv0 */ + cmdline = ""; + for (i = 1; args && args[i]; ++i) { + if (has_space(args[i]) || !args[i][0]) { + cmdline = apr_pstrcat(pool, cmdline, " \"", args[i], "\"", NULL); + } + else { + cmdline = apr_pstrcat(pool, cmdline, " ", args[i], NULL); + } + } + cmdline = apr_pstrcat(pool, shellcmd, " /C \"", argv0, cmdline, "\"", NULL); } else @@ -548,6 +548,17 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, } } + /* Handle the args, seperate from argv0 */ + cmdline = ""; + for (i = 1; args && args[i]; ++i) { + if (has_space(args[i]) || !args[i][0]) { + cmdline = apr_pstrcat(pool, cmdline, " \"", args[i], "\"", NULL); + } + else { + cmdline = apr_pstrcat(pool, cmdline, " ", args[i], NULL); + } + } + /* We must protect the cmdline args from any interpolation - this * is not a shellcmd, and the source of argv[] is untrusted. * Notice we escape ALL the cmdline args, including the quotes @@ -568,15 +579,24 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, } } else { - /* A simple command we are directly invoking. Do not pass - * the first arg to CreateProc() for APR_PROGRAM_PATH + /* A simple command we are directly invoking. + * Handle the args, seperate from argv0 */ + cmdline = argv0; + for (i = 1; args && args[i]; ++i) { + if (has_space(args[i]) || !args[i][0]) { + cmdline = apr_pstrcat(pool, cmdline, " \"", args[i], "\"", NULL); + } + else { + cmdline = apr_pstrcat(pool, cmdline, " ", args[i], NULL); + } + } + + /* Do not pass the first arg to CreateProc() for APR_PROGRAM_PATH * invocation, since it would need to be a literal and * complete file path. That is; "c:\bin\aprtest.exe" * would succeed, but "c:\bin\aprtest" or "aprtest.exe" * can fail. */ - cmdline = apr_pstrcat(pool, argv0, cmdline, NULL); - if (attr->cmdtype == APR_PROGRAM_PATH) { progname = NULL; } |