[hackers] [sbase][PATCH] Ensure commands are followed by a blank

From: Rene Kita <mail_AT_rkta.de>
Date: Tue, 26 Sep 2023 08:17:00 +0200

POSIX.1-2017 demands in Shell & Utilities under 'Commands in ed':
The e, E, f, r, and w commands shall take an optional file parameter,
separated from the command letter by one or more <blank> characters.

Ensure at least one <blank> character (as defined for the POSIX locale)
is present or error out.

Signed-off-by: Rene Kita <mail_AT_rkta.de>
---
 ed.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff --git a/ed.c b/ed.c
index b661ac5..6da845a 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -475,6 +475,24 @@ skipblank(void)
 	back(c);
 }
 
+static void
+ensureblank(void)
+{
+	char c;
+
+	switch ((c = input())) {
+	case ' ':
+	case '\t':
+		skipblank();
+	case '\n':
+		back(c);
+	case EOF:
+		break;
+	default:
+		error("unknown command");
+	}
+}
+
 static int
 getnum(void)
 {
_AT_@ -1136,10 +1154,12 @@ repeat:
 	case 'w':
 		trunc = 1;
 	case 'W':
+		ensureblank();
 		deflines(nextln(0), lastln);
 		dowrite(getfname(cmd), trunc);
 		break;
 	case 'r':
+		ensureblank();
 		if (nlines > 1)
 			goto bad_address;
 		deflines(lastln, lastln);
_AT_@ -1251,6 +1271,7 @@ repeat:
 		quit();
 		break;
 	case 'f':
+		ensureblank();
 		if (nlines > 0)
 			goto unexpected;
 		if (back(input()) != '\n')
_AT_@ -1262,6 +1283,7 @@ repeat:
 	case 'E':
 		modflag = 0;
 	case 'e':
+		ensureblank();
 		if (nlines > 0)
 			goto unexpected;
 		if (modflag)
-- 
2.42.0.rc1
Received on Tue Sep 26 2023 - 08:17:00 CEST

This archive was generated by hypermail 2.3.0 : Tue Sep 26 2023 - 09:00:38 CEST