From c153ad48825487c05fbda64357dd0a35d8c53f81 Mon Sep 17 00:00:00 2001 From: GNU Libc Maintainers Date: Wed, 26 Jan 2022 22:01:02 +0000 Subject: [PATCH] git-localedef-check-magic commit 56ea4bed7369f32e3c7c935f9e33ee38e9f78143 Author: Aurelien Jarno Date: Sun Dec 5 11:51:17 2021 +0100 localedef: check magic value on archive load [BZ #28650] localedef currently blindly trust the archive header. When passed an archive file with the wrong endianess, this leads to a segmentation fault: $ localedef --big-endian --list-archive /usr/lib/locale/locale-archive Segmentation fault (core dumped) When passed non-archive files, asserts are reported on the best case, but sometimes it can lead to a segmentation fault: $ localedef --list-archive /bin/true localedef: programs/locarchive.c:1643: show_archive_content: Assertion `used < GET (head->namehash_used)' failed. Aborted (core dumped) $ localedef --list-archive /usr/lib/locale/C.utf8/LC_COLLATE Segmentation fault (core dumped) This patch improves the user experience by looking at the magic value, which is always written, but never checked. It should still be possible to trigger a segmentation fault with crafted files, but this already catch many cases. Gbp-Pq: Topic any Gbp-Pq: Name git-localedef-check-magic.patch --- locale/programs/locarchive.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c index 6bb189ae3..28517f2e7 100644 --- a/locale/programs/locarchive.c +++ b/locale/programs/locarchive.c @@ -655,6 +655,13 @@ open_archive (struct locarhandle *ah, bool readonly) error (EXIT_FAILURE, errno, _("cannot read archive header")); } + /* Check the magic value */ + if (GET (head.magic) != AR_MAGIC) + { + (void) lockf64 (fd, F_ULOCK, sizeof (struct locarhead)); + error (EXIT_FAILURE, 0, _("bad magic value in archive header")); + } + ah->fd = fd; ah->mmaped = st.st_size; -- 2.30.2