[AArch64] fix unintialized memory

Message ID 20180425100254.GA12098@arm.com
State New
Headers show
Series
  • [AArch64] fix unintialized memory
Related show

Commit Message

Tamar Christina April 25, 2018, 10:02 a.m.
Hi All,

This patch fixes an issue where the memory for the opcode structure is not zero'd before
the first exit branch. So there is one failure mode for which uninitialized memory
is returned.

This causes weird failures when the return code is not checked before inst is used.

Regtested with check on aarch64-none-elf and no issues.

Ok for master?

Thanks,
Tamar.

opcodes/
2018-04-25  Tamar Christina  <tamar.christina@arm.com>

	* aarch64-dis.c (aarch64_opcode_decode): Moved memory clear code.

--

Comments

Tamar Christina May 1, 2018, 2:57 p.m. | #1
Ping

> -----Original Message-----

> From: binutils-owner@sourceware.org <binutils-owner@sourceware.org>

> On Behalf Of Tamar Christina

> Sent: Wednesday, April 25, 2018 11:03

> To: binutils@sourceware.org

> Cc: nd <nd@arm.com>; Richard Earnshaw <Richard.Earnshaw@arm.com>;

> Marcus Shawcroft <Marcus.Shawcroft@arm.com>

> Subject: [PATCH][Binutils][AArch64] fix unintialized memory

> 

> Hi All,

> 

> This patch fixes an issue where the memory for the opcode structure is not

> zero'd before the first exit branch. So there is one failure mode for which

> uninitialized memory is returned.

> 

> This causes weird failures when the return code is not checked before inst is

> used.

> 

> Regtested with check on aarch64-none-elf and no issues.

> 

> Ok for master?

> 

> Thanks,

> Tamar.

> 

> opcodes/

> 2018-04-25  Tamar Christina  <tamar.christina@arm.com>

> 

> 	* aarch64-dis.c (aarch64_opcode_decode): Moved memory clear

> code.

> 

> --
Nick Clifton May 1, 2018, 3:14 p.m. | #2
Hi Tamar,

> Ping


Sorry!

>> opcodes/

>> 2018-04-25  Tamar Christina  <tamar.christina@arm.com>

>>

>> 	* aarch64-dis.c (aarch64_opcode_decode): Moved memory clear

>> code.


Approved - please apply.

Cheers
  Nick
Tamar Christina May 1, 2018, 4:08 p.m. | #3
Hi Nick,

No worries, Thanks!

Cheers,
Tamar

> -----Original Message-----

> From: Nick Clifton <nickc@redhat.com>

> Sent: Tuesday, May 1, 2018 16:14

> To: Tamar Christina <Tamar.Christina@arm.com>; binutils@sourceware.org

> Cc: nd <nd@arm.com>; Richard Earnshaw <Richard.Earnshaw@arm.com>;

> Marcus Shawcroft <Marcus.Shawcroft@arm.com>

> Subject: Re: [PATCH][Binutils][AArch64] fix unintialized memory

> 

> Hi Tamar,

> 

> > Ping

> 

> Sorry!

> 

> >> opcodes/

> >> 2018-04-25  Tamar Christina  <tamar.christina@arm.com>

> >>

> >> 	* aarch64-dis.c (aarch64_opcode_decode): Moved memory clear

> code.

> 

> Approved - please apply.

> 

> Cheers

>   Nick

>

Patch

diff --git a/opcodes/aarch64-dis.c b/opcodes/aarch64-dis.c
index c63f595f682bf11b602e8cb8026b9600e8f665f6..e7bece9c1ac4b444dfcd7a35a18d1809d94c734d 100644
--- a/opcodes/aarch64-dis.c
+++ b/opcodes/aarch64-dis.c
@@ -2733,6 +2733,9 @@  aarch64_opcode_decode (const aarch64_opcode *opcode, const aarch64_insn code,
 
   assert (opcode && inst);
 
+  /* Clear inst.  */
+  memset (inst, '\0', sizeof (aarch64_inst));
+
   /* Check the base opcode.  */
   if ((code & opcode->mask) != (opcode->opcode & opcode->mask))
     {
@@ -2740,9 +2743,6 @@  aarch64_opcode_decode (const aarch64_opcode *opcode, const aarch64_insn code,
       goto decode_fail;
     }
 
-  /* Clear inst.  */
-  memset (inst, '\0', sizeof (aarch64_inst));
-
   inst->opcode = opcode;
   inst->value = code;