Module Name: src Committed By: rillig Date: Sun Feb 28 22:12:17 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh src/usr.bin/xlint/lint1: tree.c Added Files: src/tests/usr.bin/xlint/lint1: d_pr_22119.c d_pr_22119.exp Log Message: lint: fix null pointer dereference on parse error Fixes PR bin/22119. To generate a diff of this commit: cvs rdiff -u -r1.1023 -r1.1024 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.33 -r1.34 src/tests/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/d_pr_22119.c \ src/tests/usr.bin/xlint/lint1/d_pr_22119.exp cvs rdiff -u -r1.31 -r1.32 src/tests/usr.bin/xlint/lint1/t_integration.sh cvs rdiff -u -r1.231 -r1.232 src/usr.bin/xlint/lint1/tree.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1023 src/distrib/sets/lists/tests/mi:1.1024 --- src/distrib/sets/lists/tests/mi:1.1023 Sun Feb 28 20:17:13 2021 +++ src/distrib/sets/lists/tests/mi Sun Feb 28 22:12:16 2021 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1023 2021/02/28 20:17:13 rillig Exp $ +# $NetBSD: mi,v 1.1024 2021/02/28 22:12:16 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -5825,6 +5825,8 @@ ./usr/tests/usr.bin/xlint/lint1/d_nested_structs.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_nolimit_init.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_packed_structs.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/d_pr_22119.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/d_pr_22119.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_return_type.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_return_type.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/d_shift_to_narrower_type.c tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/xlint/lint1/Makefile diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.33 src/tests/usr.bin/xlint/lint1/Makefile:1.34 --- src/tests/usr.bin/xlint/lint1/Makefile:1.33 Sun Feb 28 20:17:14 2021 +++ src/tests/usr.bin/xlint/lint1/Makefile Sun Feb 28 22:12:16 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.33 2021/02/28 20:17:14 rillig Exp $ +# $NetBSD: Makefile,v 1.34 2021/02/28 22:12:16 rillig Exp $ NOMAN= # defined @@ -79,6 +79,8 @@ FILES+= d_long_double_int.exp FILES+= d_nested_structs.c FILES+= d_nolimit_init.c FILES+= d_packed_structs.c +FILES+= d_pr_22119.c +FILES+= d_pr_22119.exp FILES+= d_return_type.c FILES+= d_return_type.exp FILES+= d_shift_to_narrower_type.c Index: src/tests/usr.bin/xlint/lint1/t_integration.sh diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.31 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.32 --- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.31 Sun Feb 28 20:17:14 2021 +++ src/tests/usr.bin/xlint/lint1/t_integration.sh Sun Feb 28 22:12:16 2021 @@ -1,4 +1,4 @@ -# $NetBSD: t_integration.sh,v 1.31 2021/02/28 20:17:14 rillig Exp $ +# $NetBSD: t_integration.sh,v 1.32 2021/02/28 22:12:16 rillig Exp $ # # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. # All rights reserved. @@ -123,6 +123,7 @@ test_case c99_recursive_init test_case c9x_recursive_init test_case nested_structs test_case packed_structs +test_case pr_22119 test_case struct_init_nested test_case cast_init Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.231 src/usr.bin/xlint/lint1/tree.c:1.232 --- src/usr.bin/xlint/lint1/tree.c:1.231 Sun Feb 28 20:04:52 2021 +++ src/usr.bin/xlint/lint1/tree.c Sun Feb 28 22:12:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.231 2021/02/28 20:04:52 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.232 2021/02/28 22:12:16 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.231 2021/02/28 20:04:52 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.232 2021/02/28 22:12:16 rillig Exp $"); #endif #include <float.h> @@ -3455,6 +3455,14 @@ cast(tnode_t *tn, type_t *tp) if (tn == NULL) return NULL; + /* + * XXX: checking for tp == NULL is only a quick fix for PR 22119. + * The proper fix needs to be investigated properly. + * See d_pr_22119.c for how to get here. + */ + if (tp == NULL) + return NULL; + tn = cconv(tn); nt = tp->t_tspec; Added files: Index: src/tests/usr.bin/xlint/lint1/d_pr_22119.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_pr_22119.c:1.1 --- /dev/null Sun Feb 28 22:12:17 2021 +++ src/tests/usr.bin/xlint/lint1/d_pr_22119.c Sun Feb 28 22:12:16 2021 @@ -0,0 +1,18 @@ +/* $NetBSD: d_pr_22119.c,v 1.1 2021/02/28 22:12:16 rillig Exp $ */ +# 3 "d_pr_22119.c" + +/* + * https://gnats.netbsd.org/22119 + * + * Before 2021-02-28, lint crashed in cast() since the target type of the + * cast is NULL. +*/ + +void +func1(void) +{ + void (*f1)(void); + + f1 = (void (*)(void))p; /* expect: p undefined [99] */ + f1 = (void *()(void))p; /* crash before 2021-02-28 */ +} Index: src/tests/usr.bin/xlint/lint1/d_pr_22119.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_pr_22119.exp:1.1 --- /dev/null Sun Feb 28 22:12:17 2021 +++ src/tests/usr.bin/xlint/lint1/d_pr_22119.exp Sun Feb 28 22:12:16 2021 @@ -0,0 +1 @@ +d_pr_22119.c(16): p undefined [99]