public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] ld.so: Check for new cache format first and enhance corruption check
@ 2020-06-15  8:48 Florian Weimer
  0 siblings, 0 replies; only message in thread
From: Florian Weimer @ 2020-06-15  8:48 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e221c512c74ec42fd47b71de2981a475b38110a4

commit e221c512c74ec42fd47b71de2981a475b38110a4
Author: Florian Weimer <fweimer@redhat.com>
Date:   Mon Jun 15 09:50:14 2020 +0200

    ld.so: Check for new cache format first and enhance corruption check
    
    Now that ldconfig defaults to the new format (only), check for it
    first.  Also apply the corruption check added in commit 2954daf00bb4d
    ("Add more checks for valid ld.so.cache file (bug 18093)") to the
    new-format-only case.
    
    Suggested-by: Josh Triplett <josh@joshtriplett.org>

Diff:
---
 elf/dl-cache.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index 3eedd9afcf..93d185e788 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -199,15 +199,25 @@ _dl_load_cache_lookup (const char *name)
 					       PROT_READ);
 
       /* We can handle three different cache file formats here:
+	 - only the new format
 	 - the old libc5/glibc2.0/2.1 format
 	 - the old format with the new format in it
-	 - only the new format
 	 The following checks if the cache contains any of these formats.  */
-      if (file != MAP_FAILED && cachesize > sizeof *cache
-	  && memcmp (file, CACHEMAGIC, sizeof CACHEMAGIC - 1) == 0
+      if (file != MAP_FAILED && cachesize > sizeof *cache_new
+	  && memcmp (file, CACHEMAGIC_VERSION_NEW,
+		     sizeof CACHEMAGIC_VERSION_NEW - 1) == 0
 	  /* Check for corruption, avoiding overflow.  */
-	  && ((cachesize - sizeof *cache) / sizeof (struct file_entry)
-	      >= ((struct cache_file *) file)->nlibs))
+	  && ((cachesize - sizeof *cache_new) / sizeof (struct file_entry_new)
+	      >= ((struct cache_file_new *) file)->nlibs))
+	{
+	  cache_new = file;
+	  cache = file;
+	}
+      else if (file != MAP_FAILED && cachesize > sizeof *cache
+	       && memcmp (file, CACHEMAGIC, sizeof CACHEMAGIC - 1) == 0
+	       /* Check for corruption, avoiding overflow.  */
+	       && ((cachesize - sizeof *cache) / sizeof (struct file_entry)
+		   >= ((struct cache_file *) file)->nlibs))
 	{
 	  size_t offset;
 	  /* Looks ok.  */
@@ -223,13 +233,6 @@ _dl_load_cache_lookup (const char *name)
 			 sizeof CACHEMAGIC_VERSION_NEW - 1) != 0)
 	    cache_new = (void *) -1;
 	}
-      else if (file != MAP_FAILED && cachesize > sizeof *cache_new
-	       && memcmp (file, CACHEMAGIC_VERSION_NEW,
-			  sizeof CACHEMAGIC_VERSION_NEW - 1) == 0)
-	{
-	  cache_new = file;
-	  cache = file;
-	}
       else
 	{
 	  if (file != MAP_FAILED)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-15  8:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15  8:48 [glibc] ld.so: Check for new cache format first and enhance corruption check Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).