]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Share ap_double_quotes() code between OS2 and Win32 to use
authorWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 21 Mar 2002 16:01:31 +0000 (16:01 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 21 Mar 2002 16:01:31 +0000 (16:01 +0000)
  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
src/include/httpd.h
src/main/util.c

index 7e05c45e9a37c1bff14166cdab4b3a9c69ea82cc..36b4f13250d9edb0b393de532b11d0cb3ea9d9aa 100644 (file)
@@ -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
index 8acc53e681a780cd77a3a76dedb7daad8a11c5aa..ff22d09e8555a54d3d8f45771f70d60493ffeeab 100644 (file)
@@ -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,
index d4ed8458add180a5ce6662f73b07033272b3ab1c..fe4beb64427e8e89e71be0bb1fdd2b5141d20d03 100644 (file)
@@ -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