aboutsummaryrefslogtreecommitdiff
path: root/cpio/cpio.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpio/cpio.c')
-rw-r--r--cpio/cpio.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/cpio/cpio.c b/cpio/cpio.c
index 4b8ce79296f0..9dddf417a5a5 100644
--- a/cpio/cpio.c
+++ b/cpio/cpio.c
@@ -134,8 +134,9 @@ main(int argc, char *argv[])
struct cpio _cpio; /* Allocated on stack. */
struct cpio *cpio;
const char *errmsg;
+ char *tptr;
int uid, gid;
- int opt;
+ int opt, t;
cpio = &_cpio;
memset(cpio, 0, sizeof(*cpio));
@@ -204,9 +205,15 @@ main(int argc, char *argv[])
cpio->add_filter = opt;
break;
case 'C': /* NetBSD/OpenBSD */
- cpio->bytes_per_block = atoi(cpio->argument);
- if (cpio->bytes_per_block <= 0)
- lafe_errc(1, 0, "Invalid blocksize %s", cpio->argument);
+ errno = 0;
+ tptr = NULL;
+ t = (int)strtol(cpio->argument, &tptr, 10);
+ if (errno || t <= 0 || *(cpio->argument) == '\0' ||
+ tptr == NULL || *tptr != '\0') {
+ lafe_errc(1, 0, "Invalid blocksize: %s",
+ cpio->argument);
+ }
+ cpio->bytes_per_block = t;
break;
case 'c': /* POSIX 1997 */
cpio->format = "odc";