From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B5F3B1395E2 for ; Sat, 12 Nov 2016 07:15:40 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B4BE3E0C07; Sat, 12 Nov 2016 07:15:37 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 73B31E0C07 for ; Sat, 12 Nov 2016 07:15:37 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8E06C34166C for ; Sat, 12 Nov 2016 07:15:36 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 5B19224BC for ; Sat, 12 Nov 2016 07:15:35 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1478934609.c9842726b9464772147fe5f5e9e7f912f36f4a8a.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: paxldso.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: c9842726b9464772147fe5f5e9e7f912f36f4a8a X-VCS-Branch: master Date: Sat, 12 Nov 2016 07:15:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 1f4db6c9-9fb1-43a5-8707-b3840ff4f8c6 X-Archives-Hash: 4c1db81119d8b63670a95addbc36da36 commit: c9842726b9464772147fe5f5e9e7f912f36f4a8a Author: Mike Frysinger gentoo org> AuthorDate: Mon Jul 25 08:27:27 2016 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Sat Nov 12 07:10:09 2016 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=c9842726 paxldso: clean up local vars & types a bit Use the same types (unsigned-vs-signed) as glibc's cache code, and move relevant variables down into the scope where they're used rather than putting all of them in the top func scope. Should be no real functional changes here. paxldso.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/paxldso.c b/paxldso.c index 61d7962..5ea0bfc 100644 --- a/paxldso.c +++ b/paxldso.c @@ -47,23 +47,21 @@ static size_t ldso_cache_buf_size = 0; char *ldso_cache_lookup_lib(elfobj *elf, const char *fname) { - int fd; + unsigned int nlib; char *ret = NULL; char *strs; - const char *cachefile = root_rel_path("/etc/ld.so.cache"); - struct stat st; typedef struct { char magic[LDSO_CACHE_MAGIC_LEN]; char version[LDSO_CACHE_VER_LEN]; - int nlibs; + unsigned int nlibs; } header_t; header_t *header; typedef struct { int flags; - int sooffset; - int liboffset; + unsigned int sooffset; + unsigned int liboffset; } libentry_t; libentry_t *libent; @@ -71,6 +69,10 @@ char *ldso_cache_lookup_lib(elfobj *elf, const char *fname) return NULL; if (ldcache == NULL) { + int fd; + const char *cachefile = root_rel_path("/etc/ld.so.cache"); + struct stat st; + if (fstatat(root_fd, cachefile, &st, 0)) return NULL; @@ -104,7 +106,7 @@ char *ldso_cache_lookup_lib(elfobj *elf, const char *fname) libent = ldcache + sizeof(header_t); strs = (char *) &libent[header->nlibs]; - for (fd = 0; fd < header->nlibs; ++fd) { + for (nlib = 0; nlib < header->nlibs; ++nlib) { const char *lib; size_t lib_len; @@ -112,16 +114,16 @@ char *ldso_cache_lookup_lib(elfobj *elf, const char *fname) * 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)) + if (elf->elf_class == ELFCLASS64 && !(libent[nlib].flags & FLAG_REQUIRED_MASK)) continue; - if (elf->elf_class == ELFCLASS32 && (libent[fd].flags & FLAG_REQUIRED_MASK)) + if (elf->elf_class == ELFCLASS32 && (libent[nlib].flags & FLAG_REQUIRED_MASK)) continue; - if (strcmp(fname, strs + libent[fd].sooffset) != 0) + if (strcmp(fname, strs + libent[nlib].sooffset) != 0) continue; /* Return first hit because that is how the ldso rolls */ - lib = strs + libent[fd].liboffset; + lib = strs + libent[nlib].liboffset; lib_len = strlen(lib) + 1; if (lib_len > ldso_cache_buf_size) { ldso_cache_buf = xrealloc(ldso_cache_buf, ldso_cache_buf_size + 4096);