From: Nick Clifton <nickc@redhat.com>
Date: Wed, 19 Oct 2022 14:09:12 +0000 (+0100)
Subject: Fix an illegal memory access when parsing an ELF file containing corrupt symbol versi... 
X-Git-Tag: gdb-13-branchpoint~796
X-Git-Url: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff_plain;h=5c831a3c7f3ca98d6aba1200353311e1a1f84c70

Fix an illegal memory access when parsing an ELF file containing corrupt symbol version information.

	PR 29699
	* elf.c (_bfd_elf_slurp_version_tables): Fail if the sh_info field
	of the section header is zero.
---

diff --git a/bfd/elf.c b/bfd/elf.c
index fe00e0f9189..7cd7febcf95 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -8918,7 +8918,9 @@ _bfd_elf_slurp_version_tables (bfd *abfd, bool default_imported_symver)
 	  bfd_set_error (bfd_error_file_too_big);
 	  goto error_return_verref;
 	}
-      elf_tdata (abfd)->verref = (Elf_Internal_Verneed *) bfd_alloc (abfd, amt);
+      if (amt == 0)
+	goto error_return_verref;
+      elf_tdata (abfd)->verref = (Elf_Internal_Verneed *) bfd_zalloc (abfd, amt);
       if (elf_tdata (abfd)->verref == NULL)
 	goto error_return_verref;
 
