]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Fix undefined behavior on bad extended header
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 27 Oct 2022 20:14:52 +0000 (13:14 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 27 Oct 2022 20:20:38 +0000 (13:20 -0700)
* src/xheader.c (locate_handler): Avoid undefined behavior
if strlen(keyword) < kwlen.

src/xheader.c

index dfab650042d0356e3ff9ea5fe12e4f830c4c41fa..08cb474a81f7c5e96547dc892a8b72fb5a5a4f8d 100644 (file)
@@ -561,7 +561,7 @@ locate_handler (char const *keyword)
     if (p->prefix)
       {
        size_t kwlen = strlen (p->keyword);
-        if (keyword[kwlen] == '.' && strncmp (p->keyword, keyword, kwlen) == 0)
+       if (strncmp (p->keyword, keyword, kwlen) == 0 && keyword[kwlen] == '.')
           return p;
       }
     else
@@ -1636,7 +1636,7 @@ xattr_decoder (struct tar_stat_info *st,
                char const *keyword, char const *arg, size_t size)
 {
   char *xkey;
-  
+
   /* copy keyword */
   xkey = xstrdup (keyword);