From 642c3e06fd11b59af4550a00ec59dd254d055316 Mon Sep 17 00:00:00 2001 From: semarie Date: Tue, 23 Jun 2015 13:43:08 +0000 Subject: [PATCH] add some check before accessing data: - if section header table is be present - consistency of section header table size ok miod@ --- usr.bin/nm/elf.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/usr.bin/nm/elf.c b/usr.bin/nm/elf.c index c1033bb12e7..17906a44d47 100644 --- a/usr.bin/nm/elf.c +++ b/usr.bin/nm/elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: elf.c,v 1.28 2015/05/17 20:19:08 guenther Exp $ */ +/* $OpenBSD: elf.c,v 1.29 2015/06/23 13:43:08 semarie Exp $ */ /* * Copyright (c) 2003 Michael Shalayeff @@ -149,6 +149,16 @@ elf_load_shdrs(const char *name, FILE *fp, off_t foff, Elf_Ehdr *head) elf_fix_header(head); + if (head->e_shnum == 0) { + warnx("%s: no section header table", name); + return (NULL); + } + + if (head->e_shstrndx >= head->e_shnum) { + warnx("%s: inconsistent section header table", name); + return (NULL); + } + if ((shdr = calloc(head->e_shentsize, head->e_shnum)) == NULL) { warn("%s: malloc shdr", name); return (NULL); -- 2.20.1