[binutils-gdb] PR26441, ASAN: get_b_cc tc-cr16.c:1521

Alan Modra amodra@sourceware.org
Tue Aug 25 13:38:16 GMT 2020


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

commit d3e0baddb206bc7c5ad5beb0c4ac3db8a5feb889
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Aug 25 15:34:10 2020 +0930

    PR26441, ASAN: get_b_cc tc-cr16.c:1521
    
            PR 26441
            * config/tc-cr16.c (get_b_cc): Return NULL early if op isn't
            two or three chars, and don't bother copying.

Diff:
---
 gas/ChangeLog        | 6 ++++++
 gas/config/tc-cr16.c | 9 +++------
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 96e955140bb..f7f701c6386 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,9 @@
+2020-08-25  Alan Modra  <amodra@gmail.com>
+
+	PR 26441
+	* config/tc-cr16.c (get_b_cc): Return NULL early if op isn't
+	two or three chars, and don't bother copying.
+
 2020-08-25  Alan Modra  <amodra@gmail.com>
 
 	PR 26426
diff --git a/gas/config/tc-cr16.c b/gas/config/tc-cr16.c
index e85e5fa82f8..32eda77a4a3 100644
--- a/gas/config/tc-cr16.c
+++ b/gas/config/tc-cr16.c
@@ -1513,15 +1513,12 @@ static char *
 get_b_cc (char * op)
 {
   unsigned int i;
-  char op1[5];
 
-  for (i = 1; i < strlen (op); i++)
-     op1[i-1] = op[i];
-
-  op1[i-1] = '\0';
+  if (op[1] == 0 || (op[2] != 0 && op[3] != 0))
+    return NULL;
 
   for (i = 0; i < cr16_num_cc ; i++)
-    if (streq (op1, cr16_b_cond_tab[i]))
+    if (streq (op + 1, cr16_b_cond_tab[i]))
       return (char *) cr16_b_cond_tab[i];
 
    return NULL;


More information about the Binutils-cvs mailing list