#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readelf.c,v 1.124 2015/11/05 16:58:31 christos Exp $")
+FILE_RCSID("@(#)$File: readelf.c,v 1.125 2015/11/11 21:20:18 christos Exp $")
#endif
#ifdef BUILTIN_ELF
{
Elf32_Phdr ph32;
Elf64_Phdr ph64;
- size_t prev_vaddr = 0;
- size_t prev_off = 0;
/*
* Loop through all the program headers and find the header with
continue;
}
- if (virtaddr >= prev_vaddr && virtaddr < xph_vaddr) {
- /*
- * The previous program header was the right one, so
- * compute the file offset and return.
- */
- return prev_off + (virtaddr - prev_vaddr);
- }
-
- prev_vaddr = xph_vaddr;
- prev_off = xph_offset;
-
+ if (virtaddr >= xph_vaddr && virtaddr < xph_vaddr + xph_filesz)
+ return xph_offset + (virtaddr - xph_vaddr);
}
return 0;
}
offset = get_offset_from_virtaddr(ms, swap, clazz, fd, ph_off, ph_num,
fsize, virtaddr);
- if (pread(fd, buf, buflen, offset) != buflen) {
+ if ((buflen = pread(fd, buf, buflen, offset)) <= 0) {
file_badread(ms);
return 0;
}
size_t elsize = xauxv_sizeof;
const char *tag;
int is_string;
- uint32_t val[30];
+ uint64_t val[30];
size_t nval;
if (type != NT_AUXV || (*flags & FLAGS_IS_CORE) == 0)
for (size_t off = 0; off + elsize <= descsz; off += elsize) {
(void)memcpy(xauxv_addr, &nbuf[doff + off], xauxv_sizeof);
for (size_t i = 0; i < nval; i++)
- if (val[i] == (uint32_t)xauxv_type) {
- file_error(ms, 0, "Repeated ELF Auxv type %u",
- val[i]);
+ if (val[i] == (uint64_t)xauxv_type) {
+ file_error(ms, 0, "Repeated ELF Auxv type %ju",
+ (uintmax_t)val[i]);
return 1;
}
if (nval >= __arraycount(val)) {
file_error(ms, 0, "Too many ELF Auxv elements");
return 1;
}
- val[nval++] = (uint32_t)xauxv_type;
+ val[nval++] = (uint64_t)xauxv_type;
switch(xauxv_type) {
case AT_LINUX_EXECFN:
namesz = xnh_namesz;
descsz = xnh_descsz;
+
if ((namesz == 0) && (descsz == 0)) {
/*
* We're out of note headers.