[hackers] Re: [sbase][ed] Fix execsh() (!)

From: Quentin Rameau <quinq_AT_fifth.space>
Date: Sun, 13 Dec 2015 19:24:54 +0100

There is no need to check for escaped characters other than '%'.
Just check last cmd char against '\' when reading a '%'.
---
 ed.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/ed.c b/ed.c
index 30709f4..2851729 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -769,21 +769,15 @@ execsh(void)
 	}
 
 	while ((c = input()) != EOF && c != '\n') {
-		if (c == '\\') {
-			cmd = addchar(*p, cmd, &cap, &siz);
-			if ((c = input()) == EOF)
-				break;
-			cmd = addchar(input(), cmd, &cap, &siz);
-		}
-		if (c == '%') {
+		if (c == '%' && (siz == 0 || cmd[siz - 1] != '\\')) {
 			if (savfname[0] == '\0')
 				error("no current filename");
 			repl = 1;
 			for (p = savfname; *p; ++p)
 				cmd = addchar(*p, cmd, &cap, &siz);
-			continue;
+		} else {
+			cmd = addchar(c, cmd, &cap, &siz);
 		}
-		cmd = addchar(c, cmd, &cap, &siz);
 	}
 	cmd = addchar('\0', cmd, &cap, &siz);
 
-- 
2.6.4
Received on Sun Dec 13 2015 - 19:24:54 CET

This archive was generated by hypermail 2.3.0 : Sun Dec 13 2015 - 19:36:13 CET