From ca988435c6138887721d705931abdecd4044f934 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Tue, 21 Dec 2021 09:30:03 +0100 Subject: [PATCH] gas/ELF: avoid below-base ref in obj_elf_parse_section_letters() We would better be prepared for 'm' being the first character of the incoming string. --- gas/config/obj-elf.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index a6087a21eb3..3a9835abcaf 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -860,6 +860,17 @@ obj_elf_parse_section_letters (char *str, size_t len, { 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, size_t len, 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:" -- 2.30.2