[PATCH] gas/ELF: avoid below-base ref in obj_elf_parse_section_letters()

Jan Beulich jbeulich@suse.com
Fri Dec 17 08:18:18 GMT 2021


We would better be prepared for 'm' being the first character of the
incoming string.

--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -860,6 +860,17 @@ obj_elf_parse_section_letters (char *str
 	{
 	case 'a':
 	  attr |= SHF_ALLOC;
+	  /* Compatibility.  */
+	  if (len > 1 && str[1] == 'm')
+	    {
+	      attr |= SHF_MERGE;
+	      str++, len--;
+	      if (len > 1 && str[1] == 's')
+		{
+		  attr |= SHF_STRINGS;
+		  str++, len--;
+		}
+	    }
 	  break;
 	case 'e':
 	  attr |= SHF_EXCLUDE;
@@ -894,19 +905,6 @@ obj_elf_parse_section_letters (char *str
 	case '?':
 	  *is_clone = true;
 	  break;
-	/* Compatibility.  */
-	case 'm':
-	  if (*(str - 1) == 'a')
-	    {
-	      attr |= SHF_MERGE;
-	      if (len > 1 && str[1] == 's')
-		{
-		  attr |= SHF_STRINGS;
-		  str++, len--;
-		}
-	      break;
-	    }
-	  /* Fall through.  */
 	default:
 	  {
 	    const char *bad_msg = _("unrecognized .section attribute:"



More information about the Binutils mailing list