]> git.cworth.org Git - tar/commitdiff
Avoid undefined behavior of passing NULL to strcmp 411485
authorRaúl Sánchez Siles <rss@barracuda.es>
Tue, 4 Aug 2009 21:17:12 +0000 (14:17 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 5 Aug 2009 00:15:58 +0000 (17:15 -0700)
Having a blank line in the file passed to the -T option will cause
an entry in the argv array to be NULL. To avoid invoking undefined
behavior, we take care not to pass these NULL values to strcmp.

debian/changelog
lib/getopt.c

index 393a9e1a6567306073bf74a8077f9b9eeaecccec..5d6ecd5ff04ec718f1039f483bfc30f9a37a6991 100644 (file)
@@ -1,3 +1,10 @@
+tar (1.22-3) UNRELEASED; urgency=low
+
+  * Avoid undefined behavior of passing NULL to strcmp, closes: #411485
+    Thanks to Raúl Sánchez Siles for proposing this patch.
+
+ -- Carl Worth <cworth@cworth.org>  Tue, 04 Aug 2009 17:15:20 -0700
+
 tar (1.22-2) unstable; urgency=low
 
   * Add Carl Worth as an uploader.
index f1e6d1f7c702a4015baa324e85fe4fa41cb803e6..f1c0e1f24567aecde91a9953f571b1f8f279a5ec 100644 (file)
@@ -413,7 +413,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
         then exchange with previous non-options as if it were an option,
         then skip everything else like a non-option.  */
 
-      if (d->optind != argc && !strcmp (argv[d->optind], "--"))
+      if (d->optind != argc && argv[d->optind] && !strcmp (argv[d->optind], "--"))
        {
          d->optind++;