This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix problems parsing RISCV architecture extenstions in the assembler.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a808670465869100d4178a572da8a1503d727f3b

commit a808670465869100d4178a572da8a1503d727f3b
Author: Andrew Waterman <andrew@sifive.com>
Date:   Fri Jul 28 10:02:57 2017 +0100

    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:
---
 gas/ChangeLog         |  6 ++++++
 gas/config/tc-riscv.c | 18 +++++++-----------
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 30d349b..7b716c3 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,9 @@
+2017-07-28  Andrew Waterman  <andrew@sifive.com>
+
+	* config/tc-riscv.c (riscv_set_arch): Handle the Q subset like
+	all other subsets.
+	Obviate use-after-free.
+
 2017-07-25  Nick Clifton  <nickc@redhat.com>
 
 	PR 21739
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 55c41c5..4c644ab 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.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]