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: prevent assertion failure after pa...



details:   https://anonhg.NetBSD.org/src/rev/bd6cc05232db
branches:  trunk
changeset: 366571:bd6cc05232db
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue May 31 00:01:35 2022 +0000

description:
lint: prevent assertion failure after parse error from grammar

Instead of running into an assertion failure, the malformed input
'f=({;};}' now generates:

malformed.c(1): error: syntax error ';' [249]
malformed.c(1): warning: ({ }) is a GCC extension [320]
malformed.c(1): warning: ({ }) is a GCC extension [320]
malformed.c(1): error: cannot recover from previous errors [224]

diffstat:

 usr.bin/xlint/lint1/err.c |  17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diffs (38 lines):

diff -r 54ef56064362 -r bd6cc05232db usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Mon May 30 23:36:26 2022 +0000
+++ b/usr.bin/xlint/lint1/err.c Tue May 31 00:01:35 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.166 2022/05/20 21:18:55 rillig Exp $ */
+/*     $NetBSD: err.c,v 1.167 2022/05/31 00:01:35 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.166 2022/05/20 21:18:55 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.167 2022/05/31 00:01:35 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -591,6 +591,19 @@
 {
        const   char *fn;
 
+       /*
+        * After encountering a parse error in the grammar, lint often does
+        * not properly clean up its data structures, especially in 'dcs',
+        * the stack of declaration levels.  This often leads to assertion
+        * failures.  These cases are not interesting though, as the purpose
+        * of lint is to check syntactically valid code.  In such a case,
+        * exit gracefully.  This allows a fuzzer like afl to focus on more
+        * interesting cases instead of reporting nonsense translation units
+        * like 'f=({e:;}' or 'v(const(char););e(v){'.
+        */
+       if (sytxerr > 0)
+               norecover();
+
        fn = lbasename(curr_pos.p_file);
        (void)fflush(stdout);
        (void)fprintf(stderr,



Home | Main Index | Thread Index | Old Index