[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 01/10] elf-ops: bail out if we have no function symbols
From: |
Alex Bennée |
Subject: |
[PATCH v2 01/10] elf-ops: bail out if we have no function symbols |
Date: |
Wed, 1 Apr 2020 10:47:50 +0100 |
It's perfectly possible to have no function symbols in your elf file
and if we do the undefined behaviour sanitizer rightly complains about
us passing NULL to qsort. Check nsyms before we go ahead.
Signed-off-by: Alex Bennée <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
---
include/hw/elf_ops.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index a1411bfcab6..b5d4074d1e3 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -170,8 +170,13 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int
fd, int must_swab,
}
i++;
}
- syms = g_realloc(syms, nsyms * sizeof(*syms));
+ /* check we have symbols left */
+ if (nsyms == 0) {
+ goto fail;
+ }
+
+ syms = g_realloc(syms, nsyms * sizeof(*syms));
qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ));
for (i = 0; i < nsyms - 1; i++) {
if (syms[i].st_size == 0) {
--
2.20.1
- [PATCH for 5.0 v2 00/10] A selection of sanitiser fixes, Alex Bennée, 2020/04/01
- [PATCH v2 01/10] elf-ops: bail out if we have no function symbols,
Alex Bennée <=
- [PATCH v2 03/10] tests/tcg: remove extraneous pasting macros, Alex Bennée, 2020/04/01
- [PATCH v2 02/10] linux-user: protect fcntl64 with an #ifdef, Alex Bennée, 2020/04/01
- [PATCH v2 04/10] linux-user: more debug for init_guest_space, Alex Bennée, 2020/04/01
- [PATCH v2 05/10] target/xtensa: add FIXME for translation memory leak, Alex Bennée, 2020/04/01
- [PATCH v2 06/10] gdbstub: fix compiler complaining, Alex Bennée, 2020/04/01
- [PATCH v2 07/10] softfloat: Fix BAD_SHIFT from normalizeFloatx80Subnormal, Alex Bennée, 2020/04/01
- [PATCH v2 08/10] linux-user: factor out reading of /proc/self/maps, Alex Bennée, 2020/04/01