Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Aug 2014 22:55:25 -0700
From:      William Orr <will@worrbase.com>
To:        freebsd-current@freebsd.org
Subject:   Inconsistent behavior with dd(1)
Message-ID:  <3C86F281-D618-4B93-BBA3-2DA33AC407EC@worrbase.com>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Hey,

I found some inconsistent behavior with dd(1) when it comes to specifying arguments in -CURRENT.

 [ worr on terra ] ( ~ ) % dd if=/dev/zero of=/dev/null count=18446744073709551616
dd: count: Result too large
 [ worr on terra ] ( ~ ) % dd if=/dev/zero of=/dev/null count=18446744073709551617
dd: count: Result too large
 [ worr on terra ] ( ~ ) % dd if=/dev/zero of=/dev/null count=18446744073709551615
dd: count cannot be negative
 [ worr on terra ] ( ~ ) % dd if=/dev/zero of=/dev/null count=-18446744073709551615
1+0 records in
1+0 records out
512 bytes transferred in 0.000373 secs (1373071 bytes/sec)
 [ worr on terra ] ( ~ ) % dd if=/dev/zero of=/dev/null count=-1
dd: count cannot be negative

—

Any chance someone has the time and could take a look? https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191263

Thanks,
William Orr

—

Here’s the patch:

Index: bin/dd/args.c
===================================================================
--- bin/dd/args.c	(revision 267712)
+++ bin/dd/args.c	(working copy)
@@ -186,46 +186,31 @@
 static void
 f_bs(char *arg)
 {
-	uintmax_t res;
-
-	res = get_num(arg);
-	if (res < 1 || res > SSIZE_MAX)
-		errx(1, "bs must be between 1 and %jd", (intmax_t)SSIZE_MAX);
-	in.dbsz = out.dbsz = (size_t)res;
+	in.dbsz = out.dbsz = get_num(arg);
+	if (in.dbsz < 1 || out.dbsz < 1)
+		errx(1, "bs must be between 1 and %ju", (uintmax_t)-1);
 }
 
 static void
 f_cbs(char *arg)
 {
-	uintmax_t res;
-
-	res = get_num(arg);
-	if (res < 1 || res > SSIZE_MAX)
-		errx(1, "cbs must be between 1 and %jd", (intmax_t)SSIZE_MAX);
-	cbsz = (size_t)res;
+	cbsz = get_num(arg);
+	if (cbsz < 1)
+		errx(1, "cbs must be between 1 and %ju", (uintmax_t)-1);
 }
 
 static void
 f_count(char *arg)
 {
-	intmax_t res;
-
-	res = (intmax_t)get_num(arg);
-	if (res < 0)
-		errx(1, "count cannot be negative");
-	if (res == 0)
-		cpy_cnt = (uintmax_t)-1;
-	else
-		cpy_cnt = (uintmax_t)res;
+	cpy_cnt = get_num(arg);
 }
 
 static void
 f_files(char *arg)
 {
-
 	files_cnt = get_num(arg);
 	if (files_cnt < 1)
-		errx(1, "files must be between 1 and %jd", (uintmax_t)-1);
+		errx(1, "files must be between 1 and %ju", (uintmax_t)-1);
 }
 
 static void
@@ -241,14 +226,10 @@
 static void
 f_ibs(char *arg)
 {
-	uintmax_t res;
-
 	if (!(ddflags & C_BS)) {
-		res = get_num(arg);
-		if (res < 1 || res > SSIZE_MAX)
-			errx(1, "ibs must be between 1 and %jd",
-			    (intmax_t)SSIZE_MAX);
-		in.dbsz = (size_t)res;
+		in.dbsz = get_num(arg);
+		if (in.dbsz < 1)
+			errx(1, "ibs must be between 1 and %ju", (uintmax_t)-1);
 	}
 }
 
@@ -262,14 +243,10 @@
 static void
 f_obs(char *arg)
 {
-	uintmax_t res;
-
 	if (!(ddflags & C_BS)) {
-		res = get_num(arg);
-		if (res < 1 || res > SSIZE_MAX)
-			errx(1, "obs must be between 1 and %jd",
-			    (intmax_t)SSIZE_MAX);
-		out.dbsz = (size_t)res;
+		out.dbsz = get_num(arg);
+		if (out.dbsz < 1)
+			errx(1, "obs must be between 1 and %ju", (uintmax_t)-1);
 	}
 }
 
@@ -378,11 +355,14 @@
 	uintmax_t num, mult, prevnum;
 	char *expr;
 
+	if (val[0] == '-')
+		errx(1, "%s: cannot be negative", oper);
+
 	errno = 0;
 	num = strtouq(val, &expr, 0);
 	if (errno != 0)				/* Overflow or underflow. */
 		err(1, "%s", oper);
-	
+
 	if (expr == val)			/* No valid digits. */
 		errx(1, "%s: illegal numeric value", oper);
 
Index: bin/dd/dd.c
===================================================================
--- bin/dd/dd.c	(revision 267712)
+++ bin/dd/dd.c	(working copy)
@@ -284,8 +284,6 @@
 
 	for (;;) {
 		switch (cpy_cnt) {
-		case -1:			/* count=0 was specified */
-			return;
 		case 0:
 			break;
 		default:



[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----

iQIcBAEBAgAGBQJT7aDNAAoJEOWIWopNkblkQ1MP/0KH4PyTj907Uppcw+vZgfVr
DFw8cslqSrmDVV4H9jByFmi2H8orCwDC4Viv2gwOerZ0KkUgj0qZTJmQrYu5vPK/
xno9AIIoq5BPaCWz9Rou1/nQEMzJmxHOEuaqx5+m9mE8xMCmO75mF1c8BzuUgpAv
7oPDNokH+BOpSU70+PWXoIBu/r1bwyb8qKpBtFw1MKKLceaYPzvmmG5dlo5FGZgl
/ChfQR5bwkYMMSRABzY4DBo9+eE1MFNYYasHCA5asSdENdU02NeWwTxYtrKZtuE5
IQGGXqVutHwYJYCQgx4elr9PFXqdkI4ZtvKhwWFaItMxLVQJphYioDf7Bip3Jzsw
IBVxAEkJ9zqxK3o5JwTUobQKz0p9KOP9136P6E/pEsyiLnAnvefSmzJFHhXklKhb
CmHijeRqIAH4BT6P2a+Ut9JyMdxYh5Yt7NQCCK3uYw3xiRDZ5R9Q/knru2HCLMnu
SqUaL0rgZ200/icyfAjXnEgcbRxTD7m2/zJu2WAUd9/MaHworbgWmIsuThKH/2LV
Uy99SEMfJoiQR9oXpWUNKtTZIbPt/Aj76l1plflxnEP9CWzbn26yZC7LvLmniL5c
dy8X+PEdi4qkJ23/eWGifaa9Mg38ZdQwqkDOK52qrAdPYY9PVkevOAUFSESO+4Uf
62kWPf6bzHfeA/IXnJ4h
=14jE
-----END PGP SIGNATURE-----
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C86F281-D618-4B93-BBA3-2DA33AC407EC>