From 39ed068629d841d15d15abc95eb8e8af6cd66525 Mon Sep 17 00:00:00 2001 From: Colin Percival Date: Tue, 2 Aug 2011 04:56:27 -0400 Subject: Make sure that the argument to --strip-components is a number. Otherwise if someone accidentally omits the argument, we'll silently eat the next command line argument. (GNU tar checks this, otherwise I wouldn't bother.) Suggested by: Ralph Corderoy (via Tarsnap) SVN-Revision: 3513 --- tar/bsdtar.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tar/bsdtar.c') diff --git a/tar/bsdtar.c b/tar/bsdtar.c index d69ffb34..d508e775 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -493,7 +493,13 @@ main(int argc, char **argv) bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER; break; case OPTION_STRIP_COMPONENTS: /* GNU tar 1.15 */ - bsdtar->strip_components = atoi(bsdtar->argument); + errno = 0; + bsdtar->strip_components = strtol(bsdtar->argument, + NULL, 0); + if (errno) + lafe_errc(1, 0, + "Invalid --strip-components argument: %s", + bsdtar->argument); break; case 'T': /* GNU tar */ bsdtar->names_from_file = bsdtar->argument; -- cgit v1.2.1