* fork-child.c (fork_inferior): Quote exec_file so it can contain
authorJim Kingdon <jkingdon@engr.sgi.com>
Tue, 22 Jun 1993 04:27:00 +0000 (04:27 +0000)
committerJim Kingdon <jkingdon@engr.sgi.com>
Tue, 22 Jun 1993 04:27:00 +0000 (04:27 +0000)
funky characters.

gdb/ChangeLog
gdb/fork-child.c

index 9179c38aed71bb85fcfccb011a109c6139e0c5df..d3c16b2b94410d3a32b170303dbf9363a3a4aa58 100644 (file)
@@ -1,3 +1,8 @@
+Mon Jun 21 16:09:46 1993  Jim Kingdon  (kingdon@cygnus.com)
+
+       * fork-child.c (fork_inferior): Quote exec_file so it can contain
+       funky characters.
+
 Mon Jun 21 16:56:47 1993  Fred Fish  (fnf@cygnus.com)
 
        * Makefile.in (INCLUDE_CFLAGS):  Add BFD_INCLUDES for now, since
index 1ec7e7a73d557aa2a9dcc97311a76e9bbe225cdc..613f1eeaa10bdd0e50f93e4623e73fbb9e065130 100644 (file)
@@ -80,8 +80,11 @@ fork_inferior (exec_file, allargs, env, traceme_fun, init_trace_fun)
   shell_file = getenv ("SHELL");
   if (shell_file == NULL)
     shell_file = default_shell_file;
-  
-  len = 5 + strlen (exec_file) + 1 + strlen (allargs) + 1 + /*slop*/ 10;
+
+  /* Multiplying the length of exec_file by 4 is to account for the fact
+     that it may expand when quoted; it is a worst-case number based on
+     every character being '.  */
+  len = 5 + 4 * strlen (exec_file) + 1 + strlen (allargs) + 1 + /*slop*/ 12;
   /* If desired, concat something onto the front of ALLARGS.
      SHELL_COMMAND is the result.  */
 #ifdef SHELL_COMMAND_CONCAT
@@ -92,7 +95,23 @@ fork_inferior (exec_file, allargs, env, traceme_fun, init_trace_fun)
   shell_command[0] = '\0';
 #endif
   strcat (shell_command, "exec ");
-  strcat (shell_command, exec_file);
+
+  /* Now add exec_file, quoting as necessary.  Quoting in this style is
+     said to work with all shells.  */
+  {
+    char *p;
+
+    strcat (shell_command, "'");
+    for (p = exec_file; *p != '\0'; ++p)
+      {
+       if (*p == '\'')
+         strcat (shell_command, "'\\''");
+       else
+         strncat (shell_command, p, 1);
+      }
+    strcat (shell_command, "'");
+  }
+
   strcat (shell_command, " ");
   strcat (shell_command, allargs);
 
This page took 0.028484 seconds and 4 git commands to generate.