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 null pointer dereference on pa...



details:   https://anonhg.NetBSD.org/src/rev/5f4d8a18aee1
branches:  trunk
changeset: 959915:5f4d8a18aee1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 28 22:12:16 2021 +0000

description:
lint: fix null pointer dereference on parse error

Fixes PR bin/22119.

diffstat:

 distrib/sets/lists/tests/mi                |   4 +++-
 tests/usr.bin/xlint/lint1/Makefile         |   4 +++-
 tests/usr.bin/xlint/lint1/d_pr_22119.c     |  18 ++++++++++++++++++
 tests/usr.bin/xlint/lint1/d_pr_22119.exp   |   1 +
 tests/usr.bin/xlint/lint1/t_integration.sh |   3 ++-
 usr.bin/xlint/lint1/tree.c                 |  12 ++++++++++--
 6 files changed, 37 insertions(+), 5 deletions(-)

diffs (113 lines):

diff -r 01eb7afe5ee2 -r 5f4d8a18aee1 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Feb 28 21:39:17 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Feb 28 22:12:16 2021 +0000
@@ -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
diff -r 01eb7afe5ee2 -r 5f4d8a18aee1 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sun Feb 28 21:39:17 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sun Feb 28 22:12:16 2021 +0000
@@ -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_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
diff -r 01eb7afe5ee2 -r 5f4d8a18aee1 tests/usr.bin/xlint/lint1/d_pr_22119.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_pr_22119.c    Sun Feb 28 22:12:16 2021 +0000
@@ -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 */
+}
diff -r 01eb7afe5ee2 -r 5f4d8a18aee1 tests/usr.bin/xlint/lint1/d_pr_22119.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_pr_22119.exp  Sun Feb 28 22:12:16 2021 +0000
@@ -0,0 +1,1 @@
+d_pr_22119.c(16): p undefined [99]
diff -r 01eb7afe5ee2 -r 5f4d8a18aee1 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Sun Feb 28 21:39:17 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Sun Feb 28 22:12:16 2021 +0000
@@ -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 c9x_recursive_init
 test_case nested_structs
 test_case packed_structs
+test_case pr_22119
 test_case struct_init_nested
 
 test_case cast_init
diff -r 01eb7afe5ee2 -r 5f4d8a18aee1 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Feb 28 21:39:17 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Feb 28 22:12:16 2021 +0000
@@ -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 @@
        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;



Home | Main Index | Thread Index | Old Index