kvx: asan: out-of-bounds read
Checks
Commit Message
kvx-parse.c:parse_with_restarts does
if (!tok.insn[tok.begin])
tok.class_id = -3;
then a little later
printf_debug (1, "\nEntering rule: %d (Trying to match: (%s)[%d])\n", jump_target,
TOKEN_NAME (CLASS_ID (tok)), CLASS_ID (tok));
This results in a buffer overrun in TOKEN_NAME. Fix that.
* config/tc-kvx.h (TOKEN_NAME): Check for tok <= 0, not just -1.
@@ -37,7 +37,8 @@
#define KVX_RA_REGNO (67)
#define KVX_SP_REGNO (12)
-#define TOKEN_NAME(tok) ((tok) == -1 ? "unknown token" : env.tokens_names[(tok) - 1])
+#define TOKEN_NAME(tok) \
+ ((tok) <= 0 ? "unknown token" : env.tokens_names[(tok) - 1])
struct token_s {
char *insn;