public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Mike Frysinger (vapier)" <vapier@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c
Date: Sun, 15 Mar 2009 09:13:20 +0000	[thread overview]
Message-ID: <E1LimPI-0006vk-7f@stork.gentoo.org> (raw)

vapier      09/03/15 09:13:20

  Modified:             scanelf.c
  Log:
  cleanup lookup_cache_lib() and return first match, not last #258090

Revision  Changes    Path
1.212                pax-utils/scanelf.c

file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?rev=1.212&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?rev=1.212&content-type=text/plain
diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/scanelf.c?r1=1.211&r2=1.212

Index: scanelf.c
===================================================================
RCS file: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v
retrieving revision 1.211
retrieving revision 1.212
diff -u -r1.211 -r1.212
--- scanelf.c	15 Mar 2009 09:01:48 -0000	1.211
+++ scanelf.c	15 Mar 2009 09:13:20 -0000	1.212
@@ -1,13 +1,13 @@
 /*
  * Copyright 2003-2007 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
- * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.211 2009/03/15 09:01:48 vapier Exp $
+ * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.212 2009/03/15 09:13:20 vapier Exp $
  *
  * Copyright 2003-2007 Ned Ludd        - <solar@gentoo.org>
  * Copyright 2004-2007 Mike Frysinger  - <vapier@gentoo.org>
  */
 
-static const char *rcsid = "$Id: scanelf.c,v 1.211 2009/03/15 09:01:48 vapier Exp $";
+static const char *rcsid = "$Id: scanelf.c,v 1.212 2009/03/15 09:13:20 vapier Exp $";
 const char * const argv0 = "scanelf";
 
 #include "paxinc.h"
@@ -72,7 +72,7 @@
 
 static int match_bits = 0;
 static unsigned int match_perms = 0;
-static caddr_t ldcache = 0;
+static void *ldcache = NULL;
 static size_t ldcache_size = 0;
 static unsigned long setpax = 0UL;
 
@@ -694,10 +694,10 @@
 
 static char *lookup_cache_lib(elfobj *elf, char *fname)
 {
-	int fd = 0;
+	int fd;
 	char *strs;
 	static char buf[__PAX_UTILS_PATH_MAX] = "";
-	const char *cachefile = "/etc/ld.so.cache";
+	const char cachefile[] = "/etc/ld.so.cache";
 	struct stat st;
 
 	typedef struct {
@@ -717,35 +717,42 @@
 	if (fname == NULL)
 		return NULL;
 
-	if (ldcache == 0) {
-		if (stat(cachefile, &st) || (fd = open(cachefile, O_RDONLY)) == -1)
+	if (ldcache == NULL) {
+		if (stat(cachefile, &st))
+			return NULL;
+
+		fd = open(cachefile, O_RDONLY);
+		if (fd == -1)
 			return NULL;
 
 		/* cache these values so we only map/unmap the cache file once */
 		ldcache_size = st.st_size;
-		ldcache = mmap(0, ldcache_size, PROT_READ, MAP_SHARED, fd, 0);
-
+		header = ldcache = mmap(0, ldcache_size, PROT_READ, MAP_SHARED, fd, 0);
 		close(fd);
 
 		if (ldcache == MAP_FAILED) {
-			ldcache = 0;
+			ldcache = NULL;
 			return NULL;
 		}
 
-		if (memcmp(((header_t *) ldcache)->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN))
-			return NULL;
-		if (memcmp (((header_t *) ldcache)->version, LDSO_CACHE_VER, LDSO_CACHE_VER_LEN))
+		if (memcmp(header->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN) ||
+		    memcmp(header->version, LDSO_CACHE_VER, LDSO_CACHE_VER_LEN))
+		{
+			munmap(ldcache, ldcache_size);
+			ldcache = NULL;
 			return NULL;
-	}
+		}
+	} else
+		header = ldcache;
 
-	header = (header_t *) ldcache;
-	libent = (libentry_t *) (ldcache + sizeof(header_t));
+	libent = ldcache + sizeof(header_t);
 	strs = (char *) &libent[header->nlibs];
 
-	for (fd = 0; fd < header->nlibs; fd++) {
-		/* this should be more fine grained, but for now we assume that
-		 * diff arches will not be cached together.  and we ignore the
-		 * the different multilib mips cases. */
+	for (fd = 0; fd < header->nlibs; ++fd) {
+		/* This should be more fine grained, but for now we assume that
+		 * diff arches will not be cached together, and we ignore the
+		 * the different multilib mips cases.
+		 */
 		if (elf->elf_class == ELFCLASS64 && !(libent[fd].flags & FLAG_REQUIRED_MASK))
 			continue;
 		if (elf->elf_class == ELFCLASS32 && (libent[fd].flags & FLAG_REQUIRED_MASK))
@@ -753,10 +760,15 @@
 
 		if (strcmp(fname, strs + libent[fd].sooffset) != 0)
 			continue;
+
+		/* Return first hit because that is how the ldso rolls */
 		strncpy(buf, strs + libent[fd].liboffset, sizeof(buf));
+		break;
 	}
+
 	return buf;
 }
+
 #elif defined(__NetBSD__)
 static char *lookup_cache_lib(elfobj *elf, char *fname)
 {






             reply	other threads:[~2009-03-15  9:13 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-15  9:13 Mike Frysinger (vapier) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-02-28 22:59 [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c Mike Frysinger (vapier)
2015-02-24  6:58 Mike Frysinger (vapier)
2015-02-22  2:27 Mike Frysinger (vapier)
2015-02-22  1:38 Mike Frysinger (vapier)
2015-02-22  0:10 Mike Frysinger (vapier)
2015-02-21 19:30 Mike Frysinger (vapier)
2014-11-20  1:25 Mike Frysinger (vapier)
2014-11-05  2:02 Mike Frysinger (vapier)
2014-10-19  7:31 Mike Frysinger (vapier)
2014-03-21  5:33 Mike Frysinger (vapier)
2014-03-21  5:27 Mike Frysinger (vapier)
2014-03-20  8:08 Mike Frysinger (vapier)
2014-03-20  8:06 Mike Frysinger (vapier)
2014-01-11  0:28 Mike Frysinger (vapier)
2013-08-14 21:09 Mike Frysinger (vapier)
2013-04-16 16:22 Mike Frysinger (vapier)
2013-04-10 22:27 Mike Frysinger (vapier)
2013-04-08  6:38 Mike Frysinger (vapier)
2013-04-02 21:15 Mike Frysinger (vapier)
2012-11-30 23:25 Mike Frysinger (vapier)
2012-11-10  9:43 Mike Frysinger (vapier)
2012-11-04  8:25 Mike Frysinger (vapier)
2012-11-04  8:23 Mike Frysinger (vapier)
2012-11-04  7:48 Mike Frysinger (vapier)
2012-11-04  6:55 Mike Frysinger (vapier)
2012-08-04  6:08 Mike Frysinger (vapier)
2012-04-29  6:21 Mike Frysinger (vapier)
2012-04-29  5:41 Mike Frysinger (vapier)
2012-01-25  1:58 Mike Frysinger (vapier)
2012-01-23 23:48 Mike Frysinger (vapier)
2012-01-23 22:28 Mike Frysinger (vapier)
2011-12-21 22:17 Mike Frysinger (vapier)
2011-12-21 22:00 Mike Frysinger (vapier)
2011-12-21 17:34 Mike Frysinger (vapier)
2011-12-13  5:12 Mike Frysinger (vapier)
2011-10-13  4:49 Mike Frysinger (vapier)
2011-09-27 22:20 Mike Frysinger (vapier)
2011-09-27 19:56 Mike Frysinger (vapier)
2011-09-27 19:29 Mike Frysinger (vapier)
2011-09-27 19:21 Mike Frysinger (vapier)
2011-09-27 19:20 Mike Frysinger (vapier)
2011-09-27 17:28 Mike Frysinger (vapier)
2011-08-08  1:56 Mike Frysinger (vapier)
2011-07-30 17:08 Ned Ludd (solar)
2010-12-06 20:43 Mike Frysinger (vapier)
2010-01-15 11:56 Mike Frysinger (vapier)
2009-12-20 20:25 Mike Frysinger (vapier)
2009-12-01 10:18 Mike Frysinger (vapier)
2009-03-15  9:01 Mike Frysinger (vapier)
2009-03-15  8:53 Mike Frysinger (vapier)
2008-12-30 13:38 Mike Frysinger (vapier)
2008-12-30 12:38 Mike Frysinger (vapier)
2008-12-10 20:06 Fabian Groffen (grobian)
2008-12-10 20:05 Fabian Groffen (grobian)
2008-11-17 18:09 Diego Petteno (flameeyes)
2008-11-17 18:03 Diego Petteno (flameeyes)
2008-10-22 17:03 Diego Petteno (flameeyes)
2008-10-22 15:20 Diego Petteno (flameeyes)
2008-09-29  6:05 Mike Frysinger (vapier)
2008-09-29  6:03 Mike Frysinger (vapier)
2008-09-29  6:01 Mike Frysinger (vapier)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1LimPI-0006vk-7f@stork.gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox