]> Dogcows Code - chaz/tar/blobdiff - src/tar.c
tar: don't assume size of a sparse file chunk fits in size_t
[chaz/tar] / src / tar.c
index 5b61144c65c979fcb2c51b3e8918a59629a78fba..782ed3b5328a7778cb7afd786416803e5f3b0cbb 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -74,7 +74,7 @@
 static const char *stdin_used_by;
 
 /* Doesn't return if stdin already requested.  */
-void
+static void
 request_stdin (const char *option)
 {
   if (stdin_used_by)
@@ -1364,6 +1364,8 @@ expand_pax_option (struct tar_args *targs, const char *arg)
 }
 
 \f
+#define TAR_SIZE_SUFFIXES "bBcGgkKMmPTtw"
+
 static error_t
 parse_opt (int key, char *arg, struct argp_state *state)
 {
@@ -1506,10 +1508,15 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case 'L':
       {
        uintmax_t u;
-       if (xstrtoumax (arg, 0, 10, &u, "") != LONGINT_OK)
+       char *p;
+
+       if (xstrtoumax (arg, &p, 10, &u, TAR_SIZE_SUFFIXES) != LONGINT_OK)
          USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (arg),
                        _("Invalid tape length")));
-       tape_length_option = 1024 * (tarlong) u;
+       if (p > arg && !strchr (TAR_SIZE_SUFFIXES, p[-1]))
+         tape_length_option = 1024 * (tarlong) u;
+       else
+         tape_length_option = (tarlong) u;
        multi_volume_option = true;
       }
       break;
@@ -1961,7 +1968,8 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case RECORD_SIZE_OPTION:
       {
        uintmax_t u;
-       if (! (xstrtoumax (arg, 0, 10, &u, "") == LONGINT_OK
+
+       if (! (xstrtoumax (arg, NULL, 10, &u, TAR_SIZE_SUFFIXES) == LONGINT_OK
               && u == (size_t) u))
          USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (arg),
                        _("Invalid record size")));
@@ -2486,8 +2494,8 @@ decode_options (int argc, char **argv)
                      _("Cowardly refusing to create an empty archive")));
       if (args.compress_autodetect && archive_names
          && strcmp (archive_name_array[0], "-"))
-       set_comression_program_by_suffix (archive_name_array[0],
-                                         use_compress_program_option);
+       set_compression_program_by_suffix (archive_name_array[0],
+                                          use_compress_program_option);
       break;
 
     case EXTRACT_SUBCOMMAND:
This page took 0.021226 seconds and 4 git commands to generate.