PATCH: Fix process_section_groups in readelf

H. J. Lu hjl@lucon.org
Tue May 24 00:27:00 GMT 2005


process_section_groups doesn't check if a section member is valid.
This patch fixes it.


H.J.
----
2005-05-23  H.J. Lu  <hongjiu.lu@intel.com>

	* readelf.c (process_section_groups): Report group section
	index. Check if the section member index is valid.

--- binutils/readelf.c.grp	2005-05-22 11:35:26.000000000 -0700
+++ binutils/readelf.c	2005-05-23 15:58:05.000000000 -0700
@@ -4191,8 +4191,8 @@ process_section_groups (FILE *file)
 
 	  if (do_section_groups)
 	    {
-	      printf ("\n%s group section `%s' [%s] contains %u sections:\n",
-		      get_group_flags (entry), name, group_name, size);
+	      printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
+		      get_group_flags (entry), i, name, group_name, size);
 
 	      printf (_("   [Index]    Name\n"));
 	    }
@@ -4206,13 +4206,26 @@ process_section_groups (FILE *file)
 	      entry = byte_get (indices, 4);
 	      indices += 4;
 
+	      if (entry >= elf_header.e_shnum)
+		{
+		  error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
+			 entry, i, elf_header.e_shnum - 1);
+		  continue;
+		}
+	      else if (entry >= SHN_LORESERVE && entry <= SHN_HIRESERVE)
+		{
+		  error (_("invalid section [%5u] in group section [%5u]\n"),
+			 entry, i);
+		  continue;
+		}
+
 	      if (section_headers_groups [SECTION_HEADER_INDEX (entry)]
 		  != NULL)
 		{
 		  if (entry)
 		    {
-		      error (_("section [%5u] already in group section [%5u]\n"),
-			     entry,
+		      error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
+			     entry, i,
 			     section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
 		      continue;
 		    }



More information about the Binutils mailing list