From 85efd7f8759590df15b06d680dc2c141a499d7d3 Mon Sep 17 00:00:00 2001 From: joerg Date: Sun, 22 Sep 2019 09:51:28 +0000 Subject: Import libarchive 3.4.0 --- archivers/libarchive/files/cpio/cpio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'archivers/libarchive/files/cpio/cpio.c') diff --git a/archivers/libarchive/files/cpio/cpio.c b/archivers/libarchive/files/cpio/cpio.c index 4b8ce79296f..4fd394dea5f 100644 --- a/archivers/libarchive/files/cpio/cpio.c +++ b/archivers/libarchive/files/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"; @@ -748,8 +755,10 @@ file_to_archive(struct cpio *cpio, const char *srcpath) } if (cpio->option_rename) destpath = cpio_rename(destpath); - if (destpath == NULL) + if (destpath == NULL) { + archive_entry_free(entry); return (0); + } archive_entry_copy_pathname(entry, destpath); /* -- cgit v1.2.3