diff options
author | pi <pi@FreeBSD.org> | 2014-10-27 11:38:17 +0000 |
---|---|---|
committer | pi <pi@FreeBSD.org> | 2014-10-27 11:38:17 +0000 |
commit | 0b6ca5ce8d93243ce9ba40f73265d2c18b2c6c8a (patch) | |
tree | 6ba85fb34df7f3808f134f2cbad46ca47fb9ee12 /bin/dd/conv.c | |
parent | d92cafa3fcdd7ad1398b1373446e03dbbc40154c (diff) | |
download | FreeBSD-src-0b6ca5ce8d93243ce9ba40f73265d2c18b2c6c8a.zip FreeBSD-src-0b6ca5ce8d93243ce9ba40f73265d2c18b2c6c8a.tar.gz |
bin/dd: Fix incorrect casting of arguments
dd(1) casts many of its numeric arguments from uintmax_t to intmax_t
and back again to detect whether or not the original arguments were
negative. This caused wrong behaviour in some boundary cases:
$ dd if=/dev/zero of=/dev/null count=18446744073709551615
dd: count cannot be negative
After the fix:
$ dd if=/dev/zero of=/dev/null count=18446744073709551615
dd: count: Result too large
PR: 191263
Submitted by: will@worrbase.com
Approved by: cognet@
Diffstat (limited to 'bin/dd/conv.c')
-rw-r--r-- | bin/dd/conv.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/bin/dd/conv.c b/bin/dd/conv.c index 2ffba1e..6b1822b 100644 --- a/bin/dd/conv.c +++ b/bin/dd/conv.c @@ -133,7 +133,7 @@ block(void) */ ch = 0; for (inp = in.dbp - in.dbcnt, outp = out.dbp; in.dbcnt;) { - maxlen = MIN(cbsz, in.dbcnt); + maxlen = MIN(cbsz, (size_t)in.dbcnt); if ((t = ctab) != NULL) for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n'; ++cnt) @@ -146,7 +146,7 @@ block(void) * Check for short record without a newline. Reassemble the * input block. */ - if (ch != '\n' && in.dbcnt < cbsz) { + if (ch != '\n' && (size_t)in.dbcnt < cbsz) { (void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt); break; } @@ -228,7 +228,7 @@ unblock(void) * translation has to already be done or we might not recognize the * spaces. */ - for (inp = in.db; in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) { + for (inp = in.db; (size_t)in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) { for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t) ; if (t >= inp) { |