code: plan9front

Download patch

ref: cb7ba0e640f7226fedaecb6d1289bebabe033a3b
parent: 67c15c1e4794103dc3eeb8d76ed0b5e39b321780
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 */
 }