summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkrw <krw>2015-07-31 18:21:58 +0000
committerkrw <krw>2015-07-31 18:21:58 +0000
commit5164652e83edafb14bdc2e8b0101904134f84572 (patch)
tree017c405962ff35e8b92da0f0fc2b5d77dad80a43
parent2117201a80ac64b86a1a2b23016c2def3e4f7f28 (diff)
downloadpatch-OPENBSD_5_6.tar
patch-OPENBSD_5_6.tar.gz
Backport rev 1.53 by millert:OPENBSD_5_6
Account for newlines in substitution (s///) commands. 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. From Martin Natano. OK deraadt@
-rw-r--r--pch.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/pch.c b/pch.c
index 21e6952..41d6e01 100644
--- a/pch.c
+++ b/pch.c
@@ -1393,7 +1393,19 @@ do_ed_script(void)
(*t == 'a' || *t == 'c' || *t == 'd' || *t == 'i' || *t == 's')) {
if (pipefp != NULL)
fputs(buf, pipefp);
- if (*t != 'd') {
+ if (*t == 's') {
+ for (;;) {
+ bool continued = false;
+ t = buf + strlen(buf) - 1;
+ while (--t >= buf && *t == '\\')
+ continued = !continued;
+ if (!continued ||
+ pgets(buf, sizeof buf, pfp) == NULL)
+ break;
+ if (pipefp != NULL)
+ fputs(buf, pipefp);
+ }
+ } else if (*t != 'd') {
while (pgets(buf, sizeof buf, pfp) != NULL) {
p_input_line++;
if (pipefp != NULL)