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 endless loop on unfinished com...



details:   https://anonhg.NetBSD.org/src/rev/ffee0606d594
branches:  trunk
changeset: 1021826:ffee0606d594
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 19 20:25:57 2021 +0000

description:
lint: fix endless loop on unfinished comment at EOF

Found using afl.

diffstat:

 distrib/sets/lists/tests/mi                |   4 +++-
 tests/usr.bin/xlint/lint1/Makefile         |   4 +++-
 tests/usr.bin/xlint/lint1/lex_comment.c    |  13 +++++++++++++
 tests/usr.bin/xlint/lint1/lex_comment.exp  |   2 ++
 tests/usr.bin/xlint/lint1/t_integration.sh |   3 ++-
 usr.bin/xlint/lint1/lex.c                  |  11 ++++++++---
 6 files changed, 31 insertions(+), 6 deletions(-)

diffs (108 lines):

diff -r 9a404419fdad -r ffee0606d594 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Jun 19 19:59:01 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Jun 19 20:25:57 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1061 2021/06/19 19:59:01 rillig Exp $
+# $NetBSD: mi,v 1.1062 2021/06/19 20:25:57 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6217,6 +6217,8 @@
 ./usr/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_char.c                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_char.exp                   tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/lex_comment.c                  tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/lex_comment.exp                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_floating.c                 tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_floating.exp               tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_integer.c                  tests-usr.bin-tests     compattestfile,atf
diff -r 9a404419fdad -r ffee0606d594 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sat Jun 19 19:59:01 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sat Jun 19 20:25:57 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.63 2021/06/19 19:59:02 rillig Exp $
+# $NetBSD: Makefile,v 1.64 2021/06/19 20:25:58 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   344             # see lint1/err.c
@@ -121,6 +121,8 @@
 FILES+=                gcc_typeof_after_statement.exp
 FILES+=                lex_char.c
 FILES+=                lex_char.exp
+FILES+=                lex_comment.c
+FILES+=                lex_comment.exp
 FILES+=                lex_floating.c
 FILES+=                lex_floating.exp
 FILES+=                lex_integer.c
diff -r 9a404419fdad -r ffee0606d594 tests/usr.bin/xlint/lint1/lex_comment.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_comment.c   Sat Jun 19 20:25:57 2021 +0000
@@ -0,0 +1,13 @@
+/*     $NetBSD: lex_comment.c,v 1.1 2021/06/19 20:25:58 rillig Exp $   */
+# 3 "lex_comment.c"
+
+/*
+ * Before lex.c 1.41 from 2021-06-19, lint ran into an endless loop when it
+ * saw an unclosed comment at the end of the translation unit.  In practice
+ * this was not relevant since the translation unit always comes from the C
+ * preprocessor, which always emits a well-formed token sequence.
+ */
+
+/* expect+3: error: unterminated comment [256] */
+/* expect+2: warning: empty translation unit [272] */
+/* unclosed comment
diff -r 9a404419fdad -r ffee0606d594 tests/usr.bin/xlint/lint1/lex_comment.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_comment.exp Sat Jun 19 20:25:57 2021 +0000
@@ -0,0 +1,2 @@
+lex_comment.c(14): error: unterminated comment [256]
+lex_comment.c(14): warning: empty translation unit [272]
diff -r 9a404419fdad -r ffee0606d594 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Sat Jun 19 19:59:01 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Sat Jun 19 20:25:57 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.55 2021/06/19 19:59:02 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.56 2021/06/19 20:25:58 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -176,6 +176,7 @@
 test_case gcc_init_compound_literal
 test_case gcc_typeof_after_statement
 test_case lex_char
+test_case lex_comment
 test_case lex_floating
 test_case lex_integer
 test_case lex_string
diff -r 9a404419fdad -r ffee0606d594 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Jun 19 19:59:01 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Jun 19 20:25:57 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.40 2021/06/19 08:57:24 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.41 2021/06/19 20:25:58 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: lex.c,v 1.40 2021/06/19 08:57:24 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.41 2021/06/19 20:25:58 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -369,7 +369,12 @@
 {
        int     c;
 
-       if ((c = lex_input()) != EOF && (c &= CHAR_MASK) == '\n')
+       if ((c = lex_input()) == EOF)
+               return c;
+       c &= CHAR_MASK;
+       if (c == '\0')
+               return EOF;     /* lex returns 0 on EOF. */
+       if (c == '\n')
                lex_next_line();
        return c;
 }



Home | Main Index | Thread Index | Old Index