(tar_decode_header): use offsetof().

Sync with GNU tar b8feb2b14247d76200fd53607d3613c82b6e5b81.

Access header->buffer + offsetof (struct posix_header, magic), instead
of header->header.magic, when reading or writing the OLDGNU_MAGIC
pattern. The code violates the C standard without this change, and GCC
warns about this if fortify checking is enabled. It's not a bug on
traditional (i.e., non-debugging) platforms, but it does violate the C
standard so it should be fixed. Problem originally reported by John
Emil Karlson in
<http://lists.gnu.org/archive/html/bug-tar/2010-04/msg00023.html>.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2020-06-28 17:33:56 +03:00
parent 4a17f02b21
commit ea93350506

View File

@ -474,7 +474,7 @@ tar_decode_header (union block *header, tar_super_t * arch)
else
arch->type = TAR_USTAR;
}
else if (strcmp (header->header.magic, OLDGNU_MAGIC) == 0)
else if (strcmp (header->buffer + offsetof (struct posix_header, magic), OLDGNU_MAGIC) == 0)
arch->type = TAR_GNU;
}