[PATCH] fix crash on 'goto <reserved word>'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On code like 'goto <some reserved code>', bind_symbol() reports
an error and doesn't bind the label's ident to the goto's label
symbol.

However, at evaluation time, the ident is unconditionally
dereferenced.

Avoid the crash by checking for a null ident before dereferencing it.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 evaluate.c                 |  2 +-
 validation/goto-reserved.c | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 validation/goto-reserved.c

diff --git a/evaluate.c b/evaluate.c
index edace120f..c9ed663dd 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3593,7 +3593,7 @@ static void evaluate_goto_statement(struct statement *stmt)
 {
 	struct symbol *label = stmt->goto_label;
 
-	if (label && !label->stmt && !lookup_keyword(label->ident, NS_KEYWORD))
+	if (label && !label->stmt && label->ident && !lookup_keyword(label->ident, NS_KEYWORD))
 		sparse_error(stmt->pos, "label '%s' was not declared", show_ident(label->ident));
 
 	evaluate_expression(stmt->goto_expression);
diff --git a/validation/goto-reserved.c b/validation/goto-reserved.c
new file mode 100644
index 000000000..fbaf03e14
--- /dev/null
+++ b/validation/goto-reserved.c
@@ -0,0 +1,12 @@
+static void foo(void)
+{
+	goto return;
+}
+
+/*
+ * check-name: goto-reserved
+ *
+ * check-error-start
+goto-reserved.c:3:14: error: Trying to use reserved word 'return' as identifier
+ * check-error-end
+ */
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux