Fix bad elf data handling.

When trying to find a debug frame:

- Any file was treated as an elf file without verification.
- The index into the section header was used without verifying it is
  valid.

Both of these bugs are now fixed.

Bug: 26299490
Change-Id: Ib5ef710e6413e20243935e9451a0e0bb797894fc
diff --git a/src/dwarf/Gfind_proc_info-lsb.c b/src/dwarf/Gfind_proc_info-lsb.c
index f74b734..bc04cd1 100644
--- a/src/dwarf/Gfind_proc_info-lsb.c
+++ b/src/dwarf/Gfind_proc_info-lsb.c
@@ -112,6 +112,10 @@
   
   if (fread (&ehdr, sizeof (Elf_W (Ehdr)), 1, f) != 1)
     goto file_error;
+
+  /* Verify this is actually an elf file. */
+  if (memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0)
+    goto file_error;
   
   shstrndx = ehdr.e_shstrndx;
   
@@ -120,7 +124,8 @@
 
   fseek (f, ehdr.e_shoff, SEEK_SET);
   sec_hdrs = calloc (ehdr.e_shnum, sizeof (Elf_W (Shdr)));
-  if (sec_hdrs == NULL || fread (sec_hdrs, sizeof (Elf_W (Shdr)), ehdr.e_shnum, f) != ehdr.e_shnum)
+  if (sec_hdrs == NULL || fread (sec_hdrs, sizeof (Elf_W (Shdr)), ehdr.e_shnum, f) != ehdr.e_shnum
+      || shstrndx >= ehdr.e_shnum)
     goto file_error;
 
   Debug (4, "loading string table of size %ld\n",