diff options
author | Mark Wielaard <[email protected]> | 2015-06-27 22:07:01 +0200 |
---|---|---|
committer | Mark Wielaard <[email protected]> | 2015-06-27 22:07:01 +0200 |
commit | c08079a076420f67742be98d060500965eb22340 (patch) | |
tree | c4b6c7dfabac76c6cc24e01118c5cb3c82644b70 | |
parent | 204e36ea815440ec17bf388e8f267f0b40c2fb37 (diff) |
nm: First call elf_getdata, then allocate memory.
This catches bogus data early before we might try to allocate giant
amounts of memory.
Reported-by: Hanno Böck <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
-rw-r--r-- | src/ChangeLog | 4 | ||||
-rw-r--r-- | src/nm.c | 12 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 7d5e001b..50223a4f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2015-06-27 Mark Wielaard <[email protected]> + + * nm.c (show_symbols): First call elf_getdata, then allocate memory. + 2015-06-18 Mark Wielaard <[email protected]> * findtextrel.c (process_file): Free segments after use. @@ -1200,6 +1200,12 @@ show_symbols (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, Elf_Scn *xndxscn, } } + /* Get the data of the section. */ + Elf_Data *data = elf_getdata (scn, NULL); + Elf_Data *xndxdata = elf_getdata (xndxscn, NULL); + if (data == NULL || (xndxscn != NULL && xndxdata == NULL)) + INTERNAL_ERROR (fullname); + /* Allocate the memory. XXX We can use a dirty trick here. Since GElf_Sym == Elf64_Sym we @@ -1211,12 +1217,6 @@ show_symbols (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, Elf_Scn *xndxscn, else sym_mem = (GElf_SymX *) xmalloc (nentries * sizeof (GElf_SymX)); - /* Get the data of the section. */ - Elf_Data *data = elf_getdata (scn, NULL); - Elf_Data *xndxdata = elf_getdata (xndxscn, NULL); - if (data == NULL || (xndxscn != NULL && xndxdata == NULL)) - INTERNAL_ERROR (fullname); - /* Iterate over all symbols. */ #ifdef USE_DEMANGLE size_t demangle_buffer_len = 0; |