FreeBSD Bugzilla – Attachment 148754 Details for
Bug 191263
[patch] dd(1): Incorrect casting of arguments
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Processes arguments correctly
dd.diff (text/plain), 5.30 KB, created by
will
on 2014-10-29 05:38:15 UTC
(
hide
)
Description:
Processes arguments correctly
Filename:
MIME Type:
Creator:
will
Created:
2014-10-29 05:38:15 UTC
Size:
5.30 KB
patch
obsolete
>Index: args.c >=================================================================== >--- args.c (revision 273809) >+++ args.c (working copy) >@@ -41,6 +41,7 @@ > > #include <sys/types.h> > >+#include <ctype.h> > #include <err.h> > #include <errno.h> > #include <inttypes.h> >@@ -190,7 +191,7 @@ > > res = get_num(arg); > if (res < 1 || res > SSIZE_MAX) >- errx(1, "bs must be between 1 and %jd", (intmax_t)SSIZE_MAX); >+ errx(1, "bs must be between 1 and %zd", SSIZE_MAX); > in.dbsz = out.dbsz = (size_t)res; > } > >@@ -201,7 +202,7 @@ > > res = get_num(arg); > if (res < 1 || res > SSIZE_MAX) >- errx(1, "cbs must be between 1 and %jd", (intmax_t)SSIZE_MAX); >+ errx(1, "cbs must be between 1 and %zd", SSIZE_MAX); > cbsz = (size_t)res; > } > >@@ -208,15 +209,15 @@ > static void > f_count(char *arg) > { >- intmax_t res; >+ uintmax_t res; > >- res = (intmax_t)get_num(arg); >- if (res < 0) >- errx(1, "count cannot be negative"); >+ res = get_num(arg); >+ if (res == UINTMAX_MAX) >+ errc(1, ERANGE, "%s", oper); > if (res == 0) >- cpy_cnt = (uintmax_t)-1; >+ cpy_cnt = UINTMAX_MAX; > else >- cpy_cnt = (uintmax_t)res; >+ cpy_cnt = res; > } > > static void >@@ -225,7 +226,7 @@ > > 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 %zu", SIZE_MAX); > } > > static void >@@ -246,8 +247,8 @@ > 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); >+ errx(1, "ibs must be between 1 and %zd", >+ SSIZE_MAX); > in.dbsz = (size_t)res; > } > } >@@ -267,8 +268,8 @@ > 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); >+ errx(1, "obs must be between 1 and %zd", >+ SSIZE_MAX); > out.dbsz = (size_t)res; > } > } >@@ -378,11 +379,17 @@ > uintmax_t num, mult, prevnum; > char *expr; > >+ while (isspace(val[0])) >+ val++; >+ >+ if (val[0] == '-') >+ errx(1, "%s: cannot be negative", oper); >+ > errno = 0; >- num = strtouq(val, &expr, 0); >+ num = strtoull(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: conv.c >=================================================================== >--- conv.c (revision 273809) >+++ conv.c (working copy) >@@ -133,7 +133,7 @@ > */ > 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 @@ > * 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 @@ > * 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) { >Index: dd.c >=================================================================== >--- dd.c (revision 273809) >+++ dd.c (working copy) >@@ -168,10 +168,10 @@ > * record oriented I/O, only need a single buffer. > */ > if (!(ddflags & (C_BLOCK | C_UNBLOCK))) { >- if ((in.db = malloc(out.dbsz + in.dbsz - 1)) == NULL) >+ if ((in.db = malloc((size_t)out.dbsz + in.dbsz - 1)) == NULL) > err(1, "input buffer"); > out.db = in.db; >- } else if ((in.db = malloc(MAX(in.dbsz, cbsz) + cbsz)) == NULL || >+ } else if ((in.db = malloc(MAX((size_t)in.dbsz, cbsz) + cbsz)) == NULL || > (out.db = malloc(out.dbsz + cbsz)) == NULL) > err(1, "output buffer"); > >@@ -343,7 +343,7 @@ > ++st.in_full; > > /* Handle full input blocks. */ >- } else if ((size_t)n == in.dbsz) { >+ } else if ((size_t)n == (size_t)in.dbsz) { > in.dbcnt += in.dbrcnt = n; > ++st.in_full; > >@@ -493,7 +493,7 @@ > outp += nw; > st.bytes += nw; > >- if ((size_t)nw == n && n == out.dbsz) >+ if ((size_t)nw == n && n == (size_t)out.dbsz) > ++st.out_full; > else > ++st.out_part; >Index: dd.h >=================================================================== >--- dd.h (revision 273809) >+++ dd.h (working copy) >@@ -38,10 +38,9 @@ > typedef struct { > u_char *db; /* buffer address */ > u_char *dbp; /* current buffer I/O address */ >- /* XXX ssize_t? */ >- size_t dbcnt; /* current buffer byte count */ >- size_t dbrcnt; /* last read byte count */ >- size_t dbsz; /* block size */ >+ ssize_t dbcnt; /* current buffer byte count */ >+ ssize_t dbrcnt; /* last read byte count */ >+ ssize_t dbsz; /* block size */ > > #define ISCHR 0x01 /* character device (warn on short) */ > #define ISPIPE 0x02 /* pipe-like (see position.c) */ >Index: position.c >=================================================================== >--- position.c (revision 273809) >+++ position.c (working copy) >@@ -178,7 +178,7 @@ > n = write(out.fd, out.db, out.dbsz); > if (n == -1) > err(1, "%s", out.name); >- if ((size_t)n != out.dbsz) >+ if (n != out.dbsz) > errx(1, "%s: write failure", out.name); > } > break;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 191263
:
144014
|
147236
|
147516
|
147543
|
148683
| 148754