public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* kvx: asan: out-of-bounds read
@ 2023-08-23  1:43 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-08-23  1:43 UTC (permalink / raw)
  To: binutils; +Cc: Paul Iannetta

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.

diff --git a/gas/config/tc-kvx.h b/gas/config/tc-kvx.h
index 11787bf0532..85344cbe179 100644
--- a/gas/config/tc-kvx.h
+++ b/gas/config/tc-kvx.h
@@ -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;

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-23  1:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-23  1:43 kvx: asan: out-of-bounds read Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).