shithub: scc

Download patch

ref: bbdf237f3cb79ff55281f9a31c0a57068a375687
parent: fdf6db7e69404134489a6f6aa7c8512a69307e6f
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu May 21 10:31:30 EDT 2015

Avoid segmentation fault at EOF

When there is call to delinput() and we are at the end of
the input list, it is not desirable to go down in the
stack because in this case we can generate segmentation
faults calling getfname() or getfline().

--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -65,7 +65,7 @@
 	return 1;
 }
 
-void
+static void
 delinput(void)
 {
 	Input *ip = input;
@@ -74,6 +74,8 @@
 	if (fp) {
 		if (fclose(fp))
 			die("error reading from input file '%s'", ip->fname);
+		if (!ip->next)
+			return;
 		if (ip->fp != stdin)
 			free(ip->fname);
 	}