Skip to content

Commit

Permalink
fix auxv parser
Browse files Browse the repository at this point in the history
  • Loading branch information
sstefani committed Apr 25, 2018
1 parent badc8d2 commit 42e3f9a
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions sysdeps/linux-gnu/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,27 +350,15 @@ static int (*rdebug_fetcher(struct task *task))(struct task *, arch_addr_t, stru
return select_32_64(task, fetch_rd32, fetch_rd64);
}

static int fetch_auxv64_entry(int fd, Elf64_auxv_t *ret)
{
/* Reaching EOF is as much problem as not reading whole
* entry. */
return read(fd, ret, sizeof(*ret)) == sizeof(*ret) ? 0 : -1;
}
#ifdef _LP64
#define Elf_auxv_t Elf64_auxv_t
#else
#define Elf_auxv_t Elf32_auxv_t
#endif

static int fetch_auxv32_entry(int fd, Elf64_auxv_t *ret)
static int fetch_auxv_entry(int fd, Elf_auxv_t *ret)
{
Elf32_auxv_t auxv;

if (read(fd, &auxv, sizeof(auxv)) != sizeof(auxv))
return -1;

ret->a_type = auxv.a_type;
ret->a_un.a_val = auxv.a_un.a_val;
return 0;
}

static int (*auxv_fetcher(struct task *task)) (int, Elf64_auxv_t *) {
return select_32_64(task, fetch_auxv32_entry, fetch_auxv64_entry);
return read(fd, ret, sizeof(*ret)) == sizeof(*ret) ? 0 : -1;
}

static void linkmap_add(struct task *task, struct lt_r_debug_64 *dbg)
Expand Down Expand Up @@ -575,8 +563,9 @@ int process_get_entry(struct task *task, unsigned long *entryp, unsigned long *i
GElf_Addr at_bias = 0;

while (1) {
Elf64_auxv_t entry = { };
if (auxv_fetcher(task)(fd, &entry) < 0)
Elf_auxv_t entry = { };

if (fetch_auxv_entry(fd, &entry) < 0)
goto fail;

if (entry.a_type == AT_NULL)
Expand All @@ -589,8 +578,6 @@ int process_get_entry(struct task *task, unsigned long *entryp, unsigned long *i
case AT_ENTRY:
at_entry = entry.a_un.a_val;
break;
case AT_NULL:
break;
default:
break;
}
Expand Down

0 comments on commit 42e3f9a

Please sign in to comment.