aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-12-07 11:25:52 +1030
committerAlan Modra <amodra@gmail.com>2019-12-08 22:03:53 +1030
commit0a6aef6b6695537ac05bbe34b03907e3f1fe93d5 (patch)
treee293478d4c021fb414a90944c2232df5faec041f
parent6f765336bb07db50669efc2b8009f193c9c46ae7 (diff)
downloadgdb-0a6aef6b6695537ac05bbe34b03907e3f1fe93d5.zip
gdb-0a6aef6b6695537ac05bbe34b03907e3f1fe93d5.tar.gz
gdb-0a6aef6b6695537ac05bbe34b03907e3f1fe93d5.tar.bz2
S12Z disassembler memory leak
* s12z-opc.c (exg_sex_discrim): Don't leak memory on invalid registers.
-rw-r--r--opcodes/ChangeLog5
-rw-r--r--opcodes/s12z-opc.c24
2 files changed, 17 insertions, 12 deletions
diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index 7832435..2183b23 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-08 Alan Modra <amodra@gmail.com>
+
+ * s12z-opc.c (exg_sex_discrim): Don't leak memory on invalid
+ registers.
+
2019-12-05 Jan Beulich <jbeulich@suse.com>
* aarch64-tbl.h (aarch64_feature_crypto,
diff --git a/opcodes/s12z-opc.c b/opcodes/s12z-opc.c
index e7a3577..475c9eb 100644
--- a/opcodes/s12z-opc.c
+++ b/opcodes/s12z-opc.c
@@ -2195,32 +2195,32 @@ loop_prim_n_bytes (struct mem_read_abstraction_base *mra)
static enum optr
-exg_sex_discrim (struct mem_read_abstraction_base *mra, enum optr hint ATTRIBUTE_UNUSED)
+exg_sex_discrim (struct mem_read_abstraction_base *mra,
+ enum optr hint ATTRIBUTE_UNUSED)
{
uint8_t eb;
int status = mra->read (mra, 0, 1, &eb);
+ enum optr operator = OP_INVALID;
if (status < 0)
- return OP_INVALID;
+ return operator;
struct operand *op0 = create_register_operand ((eb & 0xf0) >> 4);
struct operand *op1 = create_register_operand (eb & 0xf);
int reg0 = ((struct register_operand *) op0)->reg;
- if (reg0 < 0 || reg0 >= S12Z_N_REGISTERS)
- return OP_INVALID;
-
int reg1 = ((struct register_operand *) op1)->reg;
- if (reg1 < 0 || reg1 >= S12Z_N_REGISTERS)
- return OP_INVALID;
-
- const struct reg *r0 = registers + reg0;
- const struct reg *r1 = registers + reg1;
+ if (reg0 >= 0 && reg0 < S12Z_N_REGISTERS
+ && reg1 >= 0 && reg1 < S12Z_N_REGISTERS)
+ {
+ const struct reg *r0 = registers + reg0;
+ const struct reg *r1 = registers + reg1;
- enum optr operator = (r0->bytes < r1->bytes) ? OP_sex : OP_exg;
+ operator = r0->bytes < r1->bytes ? OP_sex : OP_exg;
+ }
free (op0);
free (op1);
-
+
return operator;
}