Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: fix crash after syntax error in GC...
details: https://anonhg.NetBSD.org/src/rev/b921d507fcbb
branches: trunk
changeset: 364653:b921d507fcbb
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Apr 03 00:39:32 2022 +0000
description:
lint: fix crash after syntax error in GCC statement expression
Since cgram.y 1.226 from 2021-05-03.
diffstat:
tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c | 15 ++++++++++++++-
tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.exp | 1 +
usr.bin/xlint/lint1/tree.c | 11 +++++++----
3 files changed, 22 insertions(+), 5 deletions(-)
diffs (76 lines):
diff -r 4105a6a6e1c5 -r b921d507fcbb tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c
--- a/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c Sat Apr 02 22:38:45 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c Sun Apr 03 00:39:32 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: d_gcc_compound_statements1.c,v 1.7 2022/01/15 14:22:03 rillig Exp $ */
+/* $NetBSD: d_gcc_compound_statements1.c,v 1.8 2022/04/03 00:39:32 rillig Exp $ */
# 3 "d_gcc_compound_statements1.c"
/* GCC compound statement with expression */
@@ -37,3 +37,16 @@
0->e;
});
}
+
+void
+crash(void)
+{
+ /*
+ * Before tree.c 1.418 from 2022-04-03, lint dereferenced a null
+ * pointer in do_statement_expr.
+ */
+ ({
+ /* expect+1: error: syntax error ';' [249] */
+ ;
+ });
+}
diff -r 4105a6a6e1c5 -r b921d507fcbb tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.exp
--- a/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.exp Sat Apr 02 22:38:45 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.exp Sun Apr 03 00:39:32 2022 +0000
@@ -1,3 +1,4 @@
d_gcc_compound_statements1.c(24): error: syntax error 'return outside function' [249]
d_gcc_compound_statements1.c(25): error: cannot initialize 'int' from 'void' [185]
d_gcc_compound_statements1.c(37): error: type 'int' does not have member 'e' [101]
+d_gcc_compound_statements1.c(50): error: syntax error ';' [249]
diff -r 4105a6a6e1c5 -r b921d507fcbb usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sat Apr 02 22:38:45 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sun Apr 03 00:39:32 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.417 2022/04/02 22:38:45 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.418 2022/04/03 00:39:32 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.417 2022/04/02 22:38:45 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.418 2022/04/03 00:39:32 rillig Exp $");
#endif
#include <float.h>
@@ -4546,18 +4546,21 @@
{
block_level--;
mem_block_level--;
- stmt_exprs->se_sym = mktempsym(block_dup_type(tn->tn_type));
+ stmt_exprs->se_sym = tn != NULL
+ ? mktempsym(block_dup_type(tn->tn_type))
+ : NULL; /* after a syntax error */
mem_block_level++;
block_level++;
/* ({ }) is a GCC extension */
gnuism(320);
-
}
tnode_t *
end_statement_expr(void)
{
stmt_expr *se = stmt_exprs;
+ if (se->se_sym == NULL)
+ return NULL; /* after a syntax error */
tnode_t *tn = build_name(se->se_sym, false);
(void)expr_save_memory(); /* leak */
expr_restore_memory(se->se_mem);
Home |
Main Index |
Thread Index |
Old Index