6c1aee8
commit 3fcd042d26d70856e826a42b5f93dc4854d80bf0
6c1aee8
Author: Andreas Gruenbacher <agruen@gnu.org>
6c1aee8
Date:   Fri Apr 6 19:36:15 2018 +0200
6c1aee8
6c1aee8
    Invoke ed directly instead of using the shell
6c1aee8
    
6c1aee8
    * src/pch.c (do_ed_script): Invoke ed directly instead of using a shell
6c1aee8
    command to avoid quoting vulnerabilities.
6c1aee8
6c1aee8
diff --git a/src/pch.c b/src/pch.c
6c1aee8
index 4fd5a05..16e001a 100644
6c1aee8
--- a/src/pch.c
6c1aee8
+++ b/src/pch.c
6c1aee8
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
6c1aee8
 	    *outname_needs_removal = true;
6c1aee8
 	    copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
6c1aee8
 	  }
6c1aee8
-	sprintf (buf, "%s %s%s", editor_program,
6c1aee8
-		 verbosity == VERBOSE ? "" : "- ",
6c1aee8
-		 outname);
6c1aee8
 	fflush (stdout);
6c1aee8
 
6c1aee8
 	pid = fork();
6c1aee8
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
6c1aee8
 	else if (pid == 0)
6c1aee8
 	  {
6c1aee8
 	    dup2 (tmpfd, 0);
6c1aee8
-	    execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
6c1aee8
+	    assert (outname[0] != '!' && outname[0] != '-');
6c1aee8
+	    execlp (editor_program, editor_program, "-", outname, (char  *) NULL);
6c1aee8
 	    _exit (2);
6c1aee8
 	  }
6c1aee8
 	else