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 in in...



details:   https://anonhg.NetBSD.org/src/rev/6ea4192f6faa
branches:  trunk
changeset: 373610:6ea4192f6faa
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Feb 21 19:47:21 2023 +0000

description:
lint: fix null pointer dereference in invalid case expression

diffstat:

 tests/usr.bin/xlint/lint1/msg_193.c |  16 +++++++++++++++-
 usr.bin/xlint/lint1/func.c          |  12 ++++++++----
 2 files changed, 23 insertions(+), 5 deletions(-)

diffs (72 lines):

diff -r e06afe714bfe -r 6ea4192f6faa tests/usr.bin/xlint/lint1/msg_193.c
--- a/tests/usr.bin/xlint/lint1/msg_193.c       Tue Feb 21 19:32:55 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_193.c       Tue Feb 21 19:47:21 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_193.c,v 1.19 2022/06/17 18:54:53 rillig Exp $      */
+/*     $NetBSD: msg_193.c,v 1.20 2023/02/21 19:47:21 rillig Exp $      */
 # 3 "msg_193.c"
 
 // Test for message: statement not reached [193]
@@ -704,3 +704,17 @@
        /* expect+1: warning: statement not reached [193] */
        return 0;;
 }
+
+/*
+ * Before func.c 1.149 from 2023-02-21, lint crashed due to a null pointer
+ * dereference.
+ */
+void
+invalid_case_expression(void)
+{
+       switch (4) {
+       /* expect+1: error: operand of '~' has invalid type 'double' [108] */
+       case ~0.0:
+               ;
+       }
+}
diff -r e06afe714bfe -r 6ea4192f6faa usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Tue Feb 21 19:32:55 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c        Tue Feb 21 19:47:21 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.148 2023/02/18 15:18:49 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.149 2023/02/21 19:47:21 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.148 2023/02/18 15:18:49 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.149 2023/02/21 19:47:21 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -441,6 +441,7 @@
                mark_as_set(sym);
        }
 
+       /* XXX: Assuming that each label is reachable is wrong. */
        set_reached(true);
 }
 
@@ -495,13 +496,16 @@
                return;
        }
 
-       if (tn != NULL && tn->tn_op != CON) {
+       if (tn == NULL)
+               return;
+
+       if (tn->tn_op != CON) {
                /* non-constant case expression */
                error(197);
                return;
        }
 
-       if (tn != NULL && !is_integer(tn->tn_type->t_tspec)) {
+       if (!is_integer(tn->tn_type->t_tspec)) {
                /* non-integral case expression */
                error(198);
                return;



Home | Main Index | Thread Index | Old Index