Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-7]: src/usr.bin/patch Pull up following revision(s) (requested by...



details:   https://anonhg.NetBSD.org/src/rev/309b52047a1c
branches:  netbsd-7
changeset: 799522:309b52047a1c
user:      snj <snj%NetBSD.org@localhost>
date:      Fri Jul 31 16:47:13 2015 +0000

description:
Pull up following revision(s) (requested by christos in ticket #915):
        usr.bin/patch/pch.c: revision 1.28
from bitrieg:
Substitution commands might contain a newline in the replacement pattern
(escaped with a backslash before it), causing patch's understanding of
the state the ed child process is in to diverge from reality. This can
lead to patch unwillingly feeding '!' (execute shell command) lines to
ed. Finding out how to do this is left as an exercise to the reader.
XXX: pullup-7

diffstat:

 usr.bin/patch/pch.c |  19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diffs (50 lines):

diff -r c18d4e3b377a -r 309b52047a1c usr.bin/patch/pch.c
--- a/usr.bin/patch/pch.c       Thu Jul 30 16:33:38 2015 +0000
+++ b/usr.bin/patch/pch.c       Fri Jul 31 16:47:13 2015 +0000
@@ -1,7 +1,7 @@
 /*
  * $OpenBSD: pch.c,v 1.37 2007/09/02 15:19:33 deraadt Exp $
  * $DragonFly: src/usr.bin/patch/pch.c,v 1.6 2008/08/10 23:35:40 joerg Exp $
- * $NetBSD: pch.c,v 1.25.8.1 2014/11/28 09:09:19 martin Exp $
+ * $NetBSD: pch.c,v 1.25.8.2 2015/07/31 16:47:13 snj Exp $
  */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pch.c,v 1.25.8.1 2014/11/28 09:09:19 martin Exp $");
+__RCSID("$NetBSD: pch.c,v 1.25.8.2 2015/07/31 16:47:13 snj Exp $");
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -1407,6 +1407,7 @@
        char    *t;
        long    beginning_of_this_line;
        FILE    *pipefp = NULL;
+       int     continuation;
 
        if (!skip_rest_of_patch) {
                if (copy_file(filearg[0], TMPOUTNAME) < 0) {
@@ -1431,7 +1432,19 @@
                    *t == 'd' || *t == 'i' || *t == 's')) {
                        if (pipefp != NULL)
                                fputs(buf, pipefp);
-                       if (*t != 'd') {
+                       if (*t == 's') {
+                               for (;;) {
+                                       continuation = 0;
+                                       t = strchr(buf, '\0') - 1;
+                                       while (--t >= buf && *t == '\\')
+                                               continuation = !continuation;
+                                       if (!continuation ||
+                                           pgets(buf, sizeof buf, pfp) == NULL)
+                                               break;
+                                       if (pipefp != NULL)
+                                               fputs(buf, pipefp);
+                               }
+                       } else if (*t != 'd') {
                                while (pgets(buf, buf_len, pfp) != NULL) {
                                        p_input_line++;
                                        if (pipefp != NULL)



Home | Main Index | Thread Index | Old Index