aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2016-07-25 13:57:27 +0530
committerMike Frysinger <vapier@gentoo.org>2016-11-12 02:10:09 -0500
commitc9842726b9464772147fe5f5e9e7f912f36f4a8a (patch)
tree396222faa29b6d24c512920e03c90664e0fcc113
parentpaxldso: switch from a static sized path buffer to dynamic (diff)
downloadpax-utils-c9842726b9464772147fe5f5e9e7f912f36f4a8a.tar.gz
pax-utils-c9842726b9464772147fe5f5e9e7f912f36f4a8a.tar.bz2
pax-utils-c9842726b9464772147fe5f5e9e7f912f36f4a8a.zip
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.
-rw-r--r--paxldso.c24
1 files 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);