git: 9front

Download patch

ref: 4689efc783e0c4e1aab4f2a81723d394af9dfba5
parent: 42a259c14e40715b05c091b89e7375b944243e38
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jan 19 10:15:12 EST 2021

dd: error with invalid size suffixes, add 'm'

When invoking with dd with an invalid size suffix, we
silently accept the suffix. This can lead to confusion,
because lines like:

	dd -bs 1K
	dd -bs 1m

will silently copy in 1-byte increments. This has caught
people by surprise. While we're at it, megabytes are
convenient, so let's have them too.

--- a/sys/src/cmd/dd.c
+++ b/sys/src/cmd/dd.c
@@ -353,7 +353,9 @@
 		n = n*10 + *cs++ - '0';
 	for(;;)
 	switch(*cs++) {
-
+	case 'm':
+		n *= 1024*1024;
+		continue;
 	case 'k':
 		n *= 1024;
 		continue;
@@ -373,6 +375,9 @@
 			exits("range");
 		}
 		return n;
+	default:
+		fprint(2, "dd: invalid size suffix '%c'\n", cs[-1]);
+		exits("invalid");
 	}
 	/* never gets here */
 }
--