From 74f2e02bf4ceb4b0f1440f4eba247a467c45ed35 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 14 May 2007 04:15:53 +0000 Subject: [PATCH] * elf.c (bfd_elf_string_from_elf_section): Return NULL on invalid shstrndx. (bfd_elf_get_str_section): Likewise. --- bfd/ChangeLog | 6 ++++++ bfd/elf.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 81848c0631b..c8662919d9e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2007-05-14 Alan Modra + + * elf.c (bfd_elf_string_from_elf_section): Return NULL on + invalid shstrndx. + (bfd_elf_get_str_section): Likewise. + 2007-05-12 Alan Modra PR 4497 diff --git a/bfd/elf.c b/bfd/elf.c index 6e1ab9631ac..458c6797658 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -252,7 +252,9 @@ bfd_elf_get_str_section (bfd *abfd, unsigned int shindex) bfd_size_type shstrtabsize; i_shdrp = elf_elfsections (abfd); - if (i_shdrp == 0 || i_shdrp[shindex] == 0) + if (i_shdrp == 0 + || shindex >= elf_numsections (abfd) + || i_shdrp[shindex] == 0) return NULL; shstrtab = i_shdrp[shindex]->contents; @@ -291,6 +293,9 @@ bfd_elf_string_from_elf_section (bfd *abfd, if (strindex == 0) return ""; + if (elf_elfsections (abfd) == NULL || shindex >= elf_numsections (abfd)) + return NULL; + hdr = elf_elfsections (abfd)[shindex]; if (hdr->contents == NULL -- 2.30.2