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 assertion failure on malformed...



details:   https://anonhg.NetBSD.org/src/rev/19df7ea54a61
branches:  trunk
changeset: 1021831:19df7ea54a61
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 20 11:24:32 2021 +0000

description:
lint: fix assertion failure on malformed struct declaration

Found using afl.

diffstat:

 tests/usr.bin/xlint/lint1/decl_struct_member.c   |  15 ++++++++++++++-
 tests/usr.bin/xlint/lint1/decl_struct_member.exp |   3 +++
 usr.bin/xlint/lint1/decl.c                       |   7 +++++--
 3 files changed, 22 insertions(+), 3 deletions(-)

diffs (62 lines):

diff -r 63c0f4a30485 -r 19df7ea54a61 tests/usr.bin/xlint/lint1/decl_struct_member.c
--- a/tests/usr.bin/xlint/lint1/decl_struct_member.c    Sun Jun 20 11:00:18 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_struct_member.c    Sun Jun 20 11:24:32 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: decl_struct_member.c,v 1.1 2021/06/19 19:49:15 rillig Exp $    */
+/*     $NetBSD: decl_struct_member.c,v 1.2 2021/06/20 11:24:32 rillig Exp $    */
 # 3 "decl_struct_member.c"
 
 /*
@@ -10,3 +10,16 @@
 struct {
        char;                   /* expect: syntax error 'unnamed member' */
 };
+
+/*
+ * Before decl.c 1.188 from 2021-06-20, lint ran into a segmentation fault.
+ */
+struct {
+       char a(_)0              /* expect: syntax error '0' */
+}                              /* expect: ';' after last */
+/*
+ * FIXME: adding a semicolon here triggers another assertion:
+ *
+ * assertion "t == NOTSPEC" failed in deftyp at decl.c:774
+ */
+/* expect+1: cannot recover from previous errors */
diff -r 63c0f4a30485 -r 19df7ea54a61 tests/usr.bin/xlint/lint1/decl_struct_member.exp
--- a/tests/usr.bin/xlint/lint1/decl_struct_member.exp  Sun Jun 20 11:00:18 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_struct_member.exp  Sun Jun 20 11:24:32 2021 +0000
@@ -1,1 +1,4 @@
 decl_struct_member.c(11): error: syntax error 'unnamed member' [249]
+decl_struct_member.c(18): error: syntax error '0' [249]
+decl_struct_member.c(19): warning: syntax requires ';' after last struct/union member [66]
+decl_struct_member.c(26): error: cannot recover from previous errors [224]
diff -r 63c0f4a30485 -r 19df7ea54a61 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sun Jun 20 11:00:18 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sun Jun 20 11:24:32 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.187 2021/06/20 11:00:18 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.188 2021/06/20 11:24:32 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.187 2021/06/20 11:00:18 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.188 2021/06/20 11:24:32 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1806,6 +1806,9 @@
        int     n;
        sym_t   *mem;
 
+       if (tp == NULL)         /* in case of syntax errors */
+               return gettyp(INT);
+
        setcomplete(tp, true);
 
        t = tp->t_tspec;



Home | Main Index | Thread Index | Old Index