From 1b549ddfc76430707e502182d30918f15b958c64 Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Thu, 21 Mar 2002 16:01:31 +0000 Subject: [PATCH] Share ap_double_quotes() code between OS2 and Win32 to use for Win32's command.com, and introduce ap_caret_escape_args() for Win32's cmd.exe. [William Rowe] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@94089 13f79535-47bb-0310-9956-ffa450edef68 --- src/ApacheCore.def | 2 + src/include/httpd.h | 6 ++- src/main/util.c | 103 +++++++++++++++++++++++++++++++------------- 3 files changed, 80 insertions(+), 31 deletions(-) diff --git a/src/ApacheCore.def b/src/ApacheCore.def index 7e05c45e9a3..36b4f13250d 100644 --- a/src/ApacheCore.def +++ b/src/ApacheCore.def @@ -442,3 +442,5 @@ EXPORTS ap_update_child_status @434 ap_sendwithtimeout @435 ap_recvwithtimeout @436 + ap_caret_escape_args @437 + ap_double_quotes @438 diff --git a/src/include/httpd.h b/src/include/httpd.h index 8acc53e681a..ff22d09e855 100644 --- a/src/include/httpd.h +++ b/src/include/httpd.h @@ -1051,9 +1051,13 @@ API_EXPORT(char *) ap_pbase64encode(pool *p, char *string); API_EXPORT(char *) ap_uudecode(pool *p, const char *bufcoded); API_EXPORT(char *) ap_uuencode(pool *p, char *string); +#if defined(OS2) || defined(WIN32) +API_EXPORT(char *) ap_double_quotes(pool *p, const char *str); +API_EXPORT(char *) ap_caret_escape_args(pool *p, const char *str); +#endif + #ifdef OS2 void os2pathname(char *path); -char *ap_double_quotes(pool *p, char *str); #endif API_EXPORT(int) ap_regexec(const regex_t *preg, const char *string, diff --git a/src/main/util.c b/src/main/util.c index d4ed8458add..fe4beb64427 100644 --- a/src/main/util.c +++ b/src/main/util.c @@ -1457,10 +1457,13 @@ API_EXPORT(char *) ap_escape_shell_cmd(pool *p, const char *str) s = (const unsigned char *)str; for (; *s; ++s) { -#if defined(OS2) || defined(WIN32) || defined(NETWARE) - /* Don't allow '&' in parameters under OS/2. */ - /* This can be used to send commands to the shell. */ - if (*s == '&') { +#if defined(WIN32) || defined(OS2) + /* + * Newlines to Win32/OS2 CreateProcess() are ill advised. + * Convert them to spaces since they are effectively white + * space to most applications + */ + if (*s == '\r' || *s == '\n') { *d++ = ' '; continue; } @@ -2113,6 +2116,72 @@ API_EXPORT(char *) ap_uuencode(pool *p, char *string) return ap_pbase64encode(p, string); } +#if defined(OS2) || defined(WIN32) +/* quotes in the string are doubled up. + * Used to escape quotes in args passed to OS/2's cmd.exe + * and Win32's command.com + */ +API_EXPORT(char *) ap_double_quotes(pool *p, const char *str) +{ + int num_quotes = 0; + int len = 0; + char *quote_doubled_str, *dest; + + while (str[len]) { + if (str[len++] == '\"') { + num_quotes++; + } + } + + quote_doubled_str = ap_palloc(p, len + num_quotes + 1); + dest = quote_doubled_str; + + while (*str) { + if (*str == '\"') + *(dest++) = '\"'; + *(dest++) = *(str++); + } + + *dest = 0; + return quote_doubled_str; +} + +/* + * If ap_caret_escape_args resembles ap_escape_shell_cmd, it aught to. + * Taken verbatim so we can trust the integrety of this function. + */ +API_EXPORT(char *) ap_caret_escape_args(pool *p, const char *str) +{ + char *cmd; + unsigned char *d; + const unsigned char *s; + + cmd = ap_palloc(p, 2 * strlen(str) + 1); /* Be safe */ + d = (unsigned char *)cmd; + s = (const unsigned char *)str; + for (; *s; ++s) { + + /* + * Newlines to Win32/OS2 CreateProcess() are ill advised. + * Convert them to spaces since they are effectively white + * space to most applications + */ + if (*s == '\r' || *s == '\n') { + *d++ = ' '; + continue; + } + + if (TEST_CHAR(*s, T_ESCAPE_SHELL_CMD)) { + *d++ = '^'; + } + *d++ = *s; + } + *d = '\0'; + + return cmd; +} +#endif + #ifdef OS2 void os2pathname(char *path) { @@ -2138,32 +2207,6 @@ void os2pathname(char *path) strcpy(path, newpath); }; - -/* quotes in the string are doubled up. - * Used to escape quotes in args passed to OS/2's cmd.exe - */ -char *ap_double_quotes(pool *p, char *str) -{ - int num_quotes = 0; - int len = 0; - char *quote_doubled_str, *dest; - - while (str[len]) { - num_quotes += str[len++] == '\"'; - } - - quote_doubled_str = ap_palloc(p, len + num_quotes + 1); - dest = quote_doubled_str; - - while (*str) { - if (*str == '\"') - *(dest++) = '\"'; - *(dest++) = *(str++); - } - - *dest = 0; - return quote_doubled_str; -} #endif -- 2.47.2