summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2015-07-31 00:24:14 +0000
committermillert <millert@openbsd.org>2015-07-31 00:24:14 +0000
commitde55104c58d313137bd5f7b52ebccd11599a0f75 (patch)
tree2527234979825b810e48f49ddee51280e0fbe394
parentAs usual, turn off POOL_DEBUG for the release. (diff)
downloadwireguard-openbsd-de55104c58d313137bd5f7b52ebccd11599a0f75.tar.xz
wireguard-openbsd-de55104c58d313137bd5f7b52ebccd11599a0f75.zip
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--usr.bin/patch/pch.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index 36cd608bc5e..bd434f40bbc 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pch.c,v 1.52 2015/07/26 14:32:19 millert Exp $ */
+/* $OpenBSD: pch.c,v 1.53 2015/07/31 00:24:14 millert Exp $ */
/*
* patch - a program to apply diffs to original files
@@ -1402,7 +1402,19 @@ do_ed_script(void)
*t != '\0' && strchr("acdis", *t) != NULL) {
if (pipefp != NULL)
fputs(buf, pipefp);
- if (*t != 'd' && *t != 's') {
+ 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)