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 in malformed initialization
details: https://anonhg.NetBSD.org/src/rev/e69e9fb60d40
branches: trunk
changeset: 1021817:e69e9fb60d40
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jun 19 15:51:11 2021 +0000
description:
lint: fix crash in malformed initialization
diffstat:
distrib/sets/lists/tests/mi | 3 ++-
tests/usr.bin/xlint/lint1/Makefile | 3 ++-
tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c | 12 +++++++++++-
tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.exp | 2 ++
usr.bin/xlint/lint1/decl.c | 9 ++++++---
usr.bin/xlint/lint1/func.c | 13 ++++++++++---
6 files changed, 33 insertions(+), 9 deletions(-)
diffs (127 lines):
diff -r b8b7466743df -r e69e9fb60d40 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Sat Jun 19 15:23:57 2021 +0000
+++ b/distrib/sets/lists/tests/mi Sat Jun 19 15:51:11 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1058 2021/06/19 08:30:08 rillig Exp $
+# $NetBSD: mi,v 1.1059 2021/06/19 15:51:11 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6159,6 +6159,7 @@
./usr/tests/usr.bin/xlint/lint1/d_fold_test.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/d_fold_test.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/d_gcc_compound_statements2.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/d_gcc_compound_statements3.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/d_gcc_extension.c tests-usr.bin-tests compattestfile,atf
diff -r b8b7466743df -r e69e9fb60d40 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile Sat Jun 19 15:23:57 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile Sat Jun 19 15:51:11 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.60 2021/06/19 08:30:08 rillig Exp $
+# $NetBSD: Makefile,v 1.61 2021/06/19 15:51:11 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 344 # see lint1/err.c
@@ -64,6 +64,7 @@
FILES+= d_fold_test.c
FILES+= d_fold_test.exp
FILES+= d_gcc_compound_statements1.c
+FILES+= d_gcc_compound_statements1.exp
FILES+= d_gcc_compound_statements2.c
FILES+= d_gcc_compound_statements3.c
FILES+= d_gcc_extension.c
diff -r b8b7466743df -r e69e9fb60d40 tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c
--- a/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c Sat Jun 19 15:23:57 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c Sat Jun 19 15:51:11 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: d_gcc_compound_statements1.c,v 1.4 2021/03/27 13:59:18 rillig Exp $ */
+/* $NetBSD: d_gcc_compound_statements1.c,v 1.5 2021/06/19 15:51:11 rillig Exp $ */
# 3 "d_gcc_compound_statements1.c"
/* GCC compound statement with expression */
@@ -12,3 +12,13 @@
});
foo(z);
}
+
+/*
+ * Compound statements are only allowed in functions, not at file scope.
+ *
+ * Before decl.c 1.186 from 2021-06-19, lint crashed with a segmentation
+ * fault.
+ */
+int c = ({
+ return 3; /* expect: return outside function */
+}); /* expect: cannot initialize 'int' from 'void' */
diff -r b8b7466743df -r e69e9fb60d40 tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.exp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.exp Sat Jun 19 15:51:11 2021 +0000
@@ -0,0 +1,2 @@
+d_gcc_compound_statements1.c(23): error: syntax error 'return outside function' [249]
+d_gcc_compound_statements1.c(24): error: cannot initialize 'int' from 'void' [185]
diff -r b8b7466743df -r e69e9fb60d40 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Sat Jun 19 15:23:57 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c Sat Jun 19 15:51:11 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.185 2021/06/19 14:28:04 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.186 2021/06/19 15:51:11 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.185 2021/06/19 14:28:04 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.186 2021/06/19 15:51:11 rillig Exp $");
#endif
#include <sys/param.h>
@@ -3052,7 +3052,10 @@
sym_t *xsym;
lint_assert(block_level != 0);
- lint_assert(sym->s_block_level != 0);
+
+ /* example at file scope: int c = ({ return 3; }); */
+ if (sym->s_block_level == 0 && ch_isdigit(sym->s_name[0]))
+ return;
/* errors in expressions easily cause lots of these warnings */
if (nerr != 0)
diff -r b8b7466743df -r e69e9fb60d40 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c Sat Jun 19 15:23:57 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c Sat Jun 19 15:51:11 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.108 2021/05/15 19:12:14 rillig Exp $ */
+/* $NetBSD: func.c,v 1.109 2021/06/19 15:51:11 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.108 2021/05/15 19:12:14 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.109 2021/06/19 15:51:11 rillig Exp $");
#endif
#include <stdlib.h>
@@ -1049,7 +1049,14 @@
cstk_t *ci;
op_t op;
- for (ci = cstmt; ci->c_surrounding != NULL; ci = ci->c_surrounding)
+ ci = cstmt;
+ if (ci == NULL) {
+ /* syntax error '%s' */
+ error(249, "return outside function");
+ return;
+ }
+
+ for (; ci->c_surrounding != NULL; ci = ci->c_surrounding)
continue;
if (tn != NULL)
Home |
Main Index |
Thread Index |
Old Index