]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
localedef: check magic value on archive load [BZ #28650]
authorAurelien Jarno <aurelien@aurel32.net>
Sun, 5 Dec 2021 10:51:17 +0000 (11:51 +0100)
committerAurelien Jarno <aurelien@aurel32.net>
Tue, 7 Dec 2021 22:32:53 +0000 (23:32 +0100)
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.

locale/programs/locarchive.c

index eeec3ab64851e27f095af3d0ab72f88a9c3bd1ad..477499bd4082cccd3f8fca9701093158af3de718 100644 (file)
@@ -654,6 +654,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;