43c6b8
--- b/bfd/elf.c	2018-10-31 12:25:51.693217184 +0530
43c6b8
+++ a/bfd/elf.c	2018-10-31 12:27:54.243952676 +0530
43c6b8
@@ -1249,13 +1249,19 @@
43c6b8
   Elf_Internal_Shdr ** oheaders = elf_elfsections (obfd);
43c6b8
   unsigned int i;
43c6b8
 
43c6b8
-  if (section_match (oheaders[hint], iheader))
43c6b8
+  BFD_ASSERT (iheader != NULL);
43c6b8
+
43c6b8
+  /* See PR 20922 for a reproducer of the NULL test.  */
43c6b8
+  if (oheaders[hint] != NULL
43c6b8
+      && section_match (oheaders[hint], iheader))
43c6b8
     return hint;
43c6b8
 
43c6b8
   for (i = 1; i < elf_numsections (obfd); i++)
43c6b8
     {
43c6b8
       Elf_Internal_Shdr * oheader = oheaders[i];
43c6b8
 
43c6b8
+      if (oheader == NULL)
43c6b8
+	continue;      
43c6b8
       if (section_match (oheader, iheader))
43c6b8
 	/* FIXME: Do we care if there is a potential for
43c6b8
 	   multiple matches ?  */