]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Make sure that the argument to --strip-components is a number. Otherwise
authorColin Percival <cperciva@daemonology.net>
Tue, 2 Aug 2011 08:56:27 +0000 (04:56 -0400)
committerColin Percival <cperciva@daemonology.net>
Tue, 2 Aug 2011 08:56:27 +0000 (04:56 -0400)
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

index d69ffb3456513344b155064456faa759b2fa135a..d508e775235fc5b6a1fe76ea03f9f4773b77b36d 100644 (file)
@@ -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;