From: Andrew Waterman Date: Fri, 28 Jul 2017 09:02:57 +0000 (+0100) Subject: Fix problems parsing RISCV architecture extenstions in the assembler. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a808670465869100d4178a572da8a1503d727f3b;p=binutils-gdb.git Fix problems parsing RISCV architecture extenstions in the assembler. * config/tc-riscv.c (riscv_set_arch): Handle the Q subset like all other subsets. Obviate use-after-free. --- diff --git a/gas/ChangeLog b/gas/ChangeLog index 30d349b33e6..7b716c3cc3b 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,9 @@ +2017-07-28 Andrew Waterman + + * config/tc-riscv.c (riscv_set_arch): Handle the Q subset like + all other subsets. + Obviate use-after-free. + 2017-07-25 Nick Clifton PR 21739 diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 55c41c5db3c..4c644ab65ed 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -147,8 +147,8 @@ riscv_add_subset (const char *subset) static void riscv_set_arch (const char *s) { - const char *all_subsets = "imafdc"; - const char *extension = NULL; + const char *all_subsets = "imafdqc"; + char *extension = NULL; const char *p = s; riscv_clear_subsets(); @@ -173,7 +173,7 @@ riscv_set_arch (const char *s) case 'g': p++; - for ( ; *all_subsets != 'c'; all_subsets++) + for ( ; *all_subsets != 'q'; all_subsets++) { const char subset[] = {*all_subsets, '\0'}; riscv_add_subset (subset); @@ -188,7 +188,8 @@ riscv_set_arch (const char *s) { if (*p == 'x') { - char *subset = xstrdup (p), *q = subset; + char *subset = xstrdup (p); + char *q = subset; while (*++q != '\0' && *q != '_') ; @@ -200,7 +201,6 @@ riscv_set_arch (const char *s) extension = subset; riscv_add_subset (subset); p += strlen (subset); - free (subset); } else if (*p == '_') p++; @@ -211,15 +211,11 @@ riscv_set_arch (const char *s) all_subsets++; p++; } - else if (*p == 'q') - { - const char subset[] = {*p, 0}; - riscv_add_subset (subset); - p++; - } else as_fatal ("-march=%s: unsupported ISA subset `%c'", s, *p); } + + free (extension); } /* Handle of the OPCODE hash table. */