=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/nm/elf.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- src/usr.bin/nm/elf.c 2015/06/23 15:02:58 1.30 +++ src/usr.bin/nm/elf.c 2015/06/23 15:13:29 1.31 @@ -1,4 +1,4 @@ -/* $OpenBSD: elf.c,v 1.30 2015/06/23 15:02:58 semarie Exp $ */ +/* $OpenBSD: elf.c,v 1.31 2015/06/23 15:13:29 semarie Exp $ */ /* * Copyright (c) 2003 Michael Shalayeff @@ -159,7 +159,12 @@ return (NULL); } - if ((shdr = calloc(head->e_shentsize, head->e_shnum)) == NULL) { + if (head->e_shentsize < sizeof(Elf_Shdr)) { + warnx("%s: inconsistent section header size", name); + return (NULL); + } + + if ((shdr = calloc(head->e_shnum, head->e_shentsize)) == NULL) { warn("%s: malloc shdr", name); return (NULL); }