]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Resolve the win32 exec cmd bug, at least as far as some unixes support
authorWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 9 May 2001 05:17:11 +0000 (05:17 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 9 May 2001 05:17:11 +0000 (05:17 +0000)
  it.  Presume the command contains a filepath and transpose forward
  slashes to backslashes in the path.  (Note part of the bug, correctly
  identified by the poster of 7415, was the /c flag being transposed to \c).

  There has to be a better way, but at least this is now partially, and not
  entirely broken.  Command.com _does_ accept quoted file paths with spaces
  for the executable.

PR: 7415

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@89059 13f79535-47bb-0310-9956-ffa450edef68

src/CHANGES
src/main/util_script.c

index ab160349bc95ad9be24dafd0880052d7fd905434..6a1262ebc7e918e632f0fa0eba154105d8ef1258 100644 (file)
@@ -1,5 +1,8 @@
 Changes with Apache 1.3.20
 
+  *) Resolve the Win32 SSI exec cmd bug, where cmd was not executed
+     appropriately against the shell.  [William Rowe]
+
   *) Added NOESCAPE (NS) flag to RewriteRule and enabled use of
      '\' to allow escaping of special characters.  Previously
      there was no way to embed either '$' or '%' in the output
index 6474a501b8b2805de6a669e7467ef80150eea6c1..40712fbc005a94e536023b4401a0a62b87d8e5c4 100644 (file)
@@ -1102,34 +1102,21 @@ API_EXPORT(int) ap_call_exec(request_rec *r, child_info *pinfo, char *argv0,
         else /* shellcmd */
         {
             char *p, *comspec = getenv("COMSPEC");
+            const char *quotecomspec;
+            const char *quoteargv0;
             if (!comspec)
                 comspec = SHELL_PATH;
             p = strchr(comspec, '\0');
-            if ((p - comspec >= 11) && !strcasecmp(p - 11, "command.com")) 
-            {
-                /* Command.com doesn't like long paths
-                 */
-                char shortname[MAX_PATH];
-                DWORD rv = GetShortPathName(r->filename, shortname, MAX_PATH);
-                if (!rv || rv >= MAX_PATH) {
-                    ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r,
-                                  "%s is not executable; cannot translate "
-                                  "to a short path name.", r->filename);
-                    return (pid);
-                }
-                pCommand = ap_pstrcat(r->pool, "\"", comspec, "\" /C ", 
-                                      shortname, NULL);
-            }
-            else
-            {
-                /* Assume any other shell likes long paths
-                 */
-                pCommand = ap_pstrcat(r->pool, "\"", comspec, "\" /C \"", 
-                                      r->filename, "\"", NULL);
-                for (p = pCommand; *p; ++p) {
-                    if (*p == '/')
-                        *p = '\\';
-                }
+            quotecomspec = (strchr(comspec, ' ') && comspec[0] != '\"')
+                         ? "\"" : "";
+            quoteargv0 = (strchr(argv0, ' ') && argv0[0] != '\"') ? "\"" : "";
+            pCommand = ap_pstrcat(r->pool, quotecomspec, comspec, quotecomspec,
+                                  " /c ", quoteargv0, argv0, quoteargv0, NULL);
+            /* Forward slash argv[0] only */
+            for (p = pCommand + strlen(pCommand) - strlen(argv0) 
+                              - strlen(quoteargv0); *p; ++p) {
+                if (*p == '/')
+                    *p = '\\';
             }
         }