Module Name:    src
Committed By:   rillig
Date:           Tue May 31 00:01:35 UTC 2022

Modified Files:
        src/usr.bin/xlint/lint1: err.c

Log Message:
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]


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/usr.bin/xlint/lint1/err.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.166 src/usr.bin/xlint/lint1/err.c:1.167
--- src/usr.bin/xlint/lint1/err.c:1.166	Fri May 20 21:18:55 2022
+++ src/usr.bin/xlint/lint1/err.c	Tue May 31 00:01:35 2022
@@ -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 @@ assert_failed(const char *file, int line
 {
 	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,

Reply via email to