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



details:   https://anonhg.NetBSD.org/src/rev/ba796cb54354
branches:  trunk
changeset: 984045:ba796cb54354
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 19 19:49:15 2021 +0000

description:
lint: fix assertion failure in struct with unnamed member

Found using afl.

diffstat:

 distrib/sets/lists/tests/mi                      |   4 +++-
 tests/usr.bin/xlint/lint1/Makefile               |   4 +++-
 tests/usr.bin/xlint/lint1/decl_struct_member.c   |  12 ++++++++++++
 tests/usr.bin/xlint/lint1/decl_struct_member.exp |   1 +
 tests/usr.bin/xlint/lint1/t_integration.sh       |   3 ++-
 usr.bin/xlint/lint1/cgram.y                      |  16 ++++++++++------
 6 files changed, 31 insertions(+), 9 deletions(-)

diffs (112 lines):

diff -r b8bcf293bed5 -r ba796cb54354 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Jun 19 16:59:07 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Jun 19 19:49:15 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1059 2021/06/19 15:51:11 rillig Exp $
+# $NetBSD: mi,v 1.1060 2021/06/19 19:49:15 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6196,6 +6196,8 @@
 ./usr/tests/usr.bin/xlint/lint1/d_typefun.c                    tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_typename_as_var.c            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_zero_sized_arrays.c          tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/decl_struct_member.c           tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/decl_struct_member.exp         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/emit.c                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/emit.exp                       tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/emit.ln                                tests-usr.bin-tests     compattestfile,atf
diff -r b8bcf293bed5 -r ba796cb54354 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sat Jun 19 16:59:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sat Jun 19 19:49:15 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.61 2021/06/19 15:51:11 rillig Exp $
+# $NetBSD: Makefile,v 1.62 2021/06/19 19:49:15 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   344             # see lint1/err.c
@@ -100,6 +100,8 @@
 FILES+=                d_typefun.c
 FILES+=                d_typename_as_var.c
 FILES+=                d_zero_sized_arrays.c
+FILES+=                decl_struct_member.c
+FILES+=                decl_struct_member.exp
 FILES+=                emit.c
 FILES+=                emit.exp
 FILES+=                emit.ln
diff -r b8bcf293bed5 -r ba796cb54354 tests/usr.bin/xlint/lint1/decl_struct_member.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_struct_member.c    Sat Jun 19 19:49:15 2021 +0000
@@ -0,0 +1,12 @@
+/*     $NetBSD: decl_struct_member.c,v 1.1 2021/06/19 19:49:15 rillig Exp $    */
+# 3 "decl_struct_member.c"
+
+/*
+ * Before cgram.y 1.228 from 2021-06-19, lint ran into an assertion failure:
+ *
+ * "is_struct_or_union(dcs->d_type->t_tspec)" at cgram.y:846
+ */
+
+struct {
+       char;                   /* expect: syntax error 'unnamed member' */
+};
diff -r b8bcf293bed5 -r ba796cb54354 tests/usr.bin/xlint/lint1/decl_struct_member.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_struct_member.exp  Sat Jun 19 19:49:15 2021 +0000
@@ -0,0 +1,1 @@
+decl_struct_member.c(11): error: syntax error 'unnamed member' [249]
diff -r b8bcf293bed5 -r ba796cb54354 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Sat Jun 19 16:59:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Sat Jun 19 19:49:15 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.53 2021/06/19 08:30:08 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.54 2021/06/19 19:49:15 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -166,6 +166,7 @@
 test_case d_typefun
 test_case d_typename_as_var
 test_case d_zero_sized_arrays
+test_case decl_struct_member
 test_case emit
 test_case expr_range
 test_case feat_stacktrace
diff -r b8bcf293bed5 -r ba796cb54354 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Jun 19 16:59:07 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Jun 19 19:49:15 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.227 2021/06/19 15:23:57 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.228 2021/06/19 19:49:15 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.227 2021/06/19 15:23:57 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.228 2021/06/19 19:49:15 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -843,10 +843,14 @@
                if (!Sflag)
                        /* anonymous struct/union members is a C9X feature */
                        warning(49);
-               lint_assert(is_struct_or_union(dcs->d_type->t_tspec));
-               $$ = dcs->d_type->t_str->sou_first_member;
-               /* add all the members of the anonymous struct/union */
-               anonymize($$);
+               if (is_struct_or_union(dcs->d_type->t_tspec)) {
+                       $$ = dcs->d_type->t_str->sou_first_member;
+                       /* add all the members of the anonymous struct/union */
+                       anonymize($$);
+               } else {
+                       /* syntax error '%s' */
+                       error(249, "unnamed member");
+               }
          }
        | error {
                symtyp = FVFT;



Home | Main Index | Thread Index | Old Index