arm: fix array-out-of-bounds upon register parsing error

Message ID 3b18fee5-177e-4626-dd64-2538462004cc@suse.com
State New
Headers show
Series
  • arm: fix array-out-of-bounds upon register parsing error
Related show

Commit Message

Libor Bukata via Binutils June 10, 2021, 7:43 a.m.
Despite the comment ahead of the enum explicitly pointing out the need
to also update the corresponding array, 1b8833198c0 ("Add support for
MVE instructions: vcmp and vpt") failed to do so. Oddly enough the issue
appears to be spotted only by rather old gcc (4.3-ish in my case).

gas/
2021-06-XX  Jan Beulich  <jbeulich@suse.com>

	* config/tc-arm.c (reg_expected_msgs): Add REG_TYPE_ZR entry.

Comments

Libor Bukata via Binutils June 10, 2021, 10:29 a.m. | #1
OK.

I wonder if we could somehow build in an assert to check this.  Even 
better would be a static assertion during compilation, but that might be 
harder.

On 10/06/2021 08:43, Jan Beulich via Binutils wrote:
> Despite the comment ahead of the enum explicitly pointing out the need

> to also update the corresponding array, 1b8833198c0 ("Add support for

> MVE instructions: vcmp and vpt") failed to do so. Oddly enough the issue

> appears to be spotted only by rather old gcc (4.3-ish in my case).

> 

> gas/

> 2021-06-XX  Jan Beulich  <jbeulich@suse.com>

> 

> 	* config/tc-arm.c (reg_expected_msgs): Add REG_TYPE_ZR entry.

> 

> --- a/gas/config/tc-arm.c

> +++ b/gas/config/tc-arm.c

> @@ -729,7 +729,8 @@ const char * const reg_expected_msgs[] =

>     [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),

>     [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),

>     [REG_TYPE_MQ]	    = N_("MVE vector register expected"),

> -  [REG_TYPE_RNB]    = ""

> +  [REG_TYPE_RNB]    = "",

> +  [REG_TYPE_ZR]     = N_("ZR register expected"),

>   };

>   

>   /* Some well known registers that we refer to directly elsewhere.  */

>
Libor Bukata via Binutils June 10, 2021, 10:45 a.m. | #2
On 10.06.2021 12:29, Richard Earnshaw wrote:
> OK.


Thanks, committed.

> I wonder if we could somehow build in an assert to check this.  Even 

> better would be a static assertion during compilation, but that might be 

> harder.


A Linux-like (or wherever its origin) BUILD_BUG_ON() shouldn't be that
hard to put in, even if _Static_assert() can't be used (unconditionally)
just yet.

Jan

Patch

--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -729,7 +729,8 @@  const char * const reg_expected_msgs[] =
   [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
   [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
   [REG_TYPE_MQ]	    = N_("MVE vector register expected"),
-  [REG_TYPE_RNB]    = ""
+  [REG_TYPE_RNB]    = "",
+  [REG_TYPE_ZR]     = N_("ZR register expected"),
 };
 
 /* Some well known registers that we refer to directly elsewhere.  */