From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1LimPJ-0006zx-TB for garchives@archives.gentoo.org; Sun, 15 Mar 2009 09:13:22 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 44A64E026B; Sun, 15 Mar 2009 09:13:21 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id F3A63E026B for ; Sun, 15 Mar 2009 09:13:20 +0000 (UTC) Received: from stork.gentoo.org (stork.gentoo.org [64.127.104.133]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id 8C5AD64904 for ; Sun, 15 Mar 2009 09:13:20 +0000 (UTC) Received: from vapier by stork.gentoo.org with local (Exim 4.69) (envelope-from ) id 1LimPI-0006vk-7f for gentoo-commits@lists.gentoo.org; Sun, 15 Mar 2009 09:13:20 +0000 From: "Mike Frysinger (vapier)" To: gentoo-commits@lists.gentoo.org Reply-To: gentoo-dev@lists.gentoo.org, vapier@gentoo.org Subject: [gentoo-commits] gentoo-projects commit in pax-utils: scanelf.c X-VCS-Repository: gentoo-projects X-VCS-Files: scanelf.c X-VCS-Directories: pax-utils X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger Content-Type: text/plain; charset=utf8 Message-Id: Sender: Mike Frysinger Date: Sun, 15 Mar 2009 09:13:20 +0000 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 65c744cf-740c-4fd1-ad9a-eb5c956c3eec X-Archives-Hash: 7d0a7bb3785d56b341dd3a2a4876c071 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/sca= nelf.c?rev=3D1.212&view=3Dmarkup plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/sca= nelf.c?rev=3D1.212&content-type=3Dtext/plain diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/sca= nelf.c?r1=3D1.211&r2=3D1.212 Index: scanelf.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 200= 9/03/15 09:01:48 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.212 200= 9/03/15 09:13:20 vapier Exp $ * * Copyright 2003-2007 Ned Ludd - * Copyright 2004-2007 Mike Frysinger - */ =20 -static const char *rcsid =3D "$Id: scanelf.c,v 1.211 2009/03/15 09:01:48= vapier Exp $"; +static const char *rcsid =3D "$Id: scanelf.c,v 1.212 2009/03/15 09:13:20= vapier Exp $"; const char * const argv0 =3D "scanelf"; =20 #include "paxinc.h" @@ -72,7 +72,7 @@ =20 static int match_bits =3D 0; static unsigned int match_perms =3D 0; -static caddr_t ldcache =3D 0; +static void *ldcache =3D NULL; static size_t ldcache_size =3D 0; static unsigned long setpax =3D 0UL; =20 @@ -694,10 +694,10 @@ =20 static char *lookup_cache_lib(elfobj *elf, char *fname) { - int fd =3D 0; + int fd; char *strs; static char buf[__PAX_UTILS_PATH_MAX] =3D ""; - const char *cachefile =3D "/etc/ld.so.cache"; + const char cachefile[] =3D "/etc/ld.so.cache"; struct stat st; =20 typedef struct { @@ -717,35 +717,42 @@ if (fname =3D=3D NULL) return NULL; =20 - if (ldcache =3D=3D 0) { - if (stat(cachefile, &st) || (fd =3D open(cachefile, O_RDONLY)) =3D=3D = -1) + if (ldcache =3D=3D NULL) { + if (stat(cachefile, &st)) + return NULL; + + fd =3D open(cachefile, O_RDONLY); + if (fd =3D=3D -1) return NULL; =20 /* cache these values so we only map/unmap the cache file once */ ldcache_size =3D st.st_size; - ldcache =3D mmap(0, ldcache_size, PROT_READ, MAP_SHARED, fd, 0); - + header =3D ldcache =3D mmap(0, ldcache_size, PROT_READ, MAP_SHARED, fd= , 0); close(fd); =20 if (ldcache =3D=3D MAP_FAILED) { - ldcache =3D 0; + ldcache =3D NULL; return NULL; } =20 - 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_CACH= E_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 =3D NULL; return NULL; - } + } + } else + header =3D ldcache; =20 - header =3D (header_t *) ldcache; - libent =3D (libentry_t *) (ldcache + sizeof(header_t)); + libent =3D ldcache + sizeof(header_t); strs =3D (char *) &libent[header->nlibs]; =20 - for (fd =3D 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 =3D 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 =3D=3D ELFCLASS64 && !(libent[fd].flags & FLAG_REQU= IRED_MASK)) continue; if (elf->elf_class =3D=3D ELFCLASS32 && (libent[fd].flags & FLAG_REQUI= RED_MASK)) @@ -753,10 +760,15 @@ =20 if (strcmp(fname, strs + libent[fd].sooffset) !=3D 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) {