Fix undefined behavior on bad extended header

* src/xheader.c (locate_handler): Avoid undefined behavior
if strlen(keyword) < kwlen.
This commit is contained in:
Paul Eggert
2022-10-27 13:14:52 -07:00
parent 17debecd73
commit de64229632

View 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);