[PATCH] fix uninitialized value after include(), fixes test001

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri, 6 May 2016 22:18:53 +0200

The issue manifests after the line "#include <stdio.h>" is parsed.
The codeflow is like this:

- in cpp.c calls (*bp->fun)();
- this calls include().
- in includefile() calls addinput(path);
- ip->begin[0] = uninitialized
- in include() its_done label next() is called.
- next() checks ip->begin[0].

This is triggered when using OpenBSD with MALLOC_OPTIONS="J" set,
this option fills allocated and free'd memory with junk (useful for finding
this kind of issues).
---
 cc1/lex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cc1/lex.c b/cc1/lex.c
index 3aff6d3..935cb40 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -30,6 +30,7 @@ allocinput(char *fname, FILE *fp)
 	ip = xmalloc(sizeof(Input));
 	ip->fname = xstrdup(fname);
 	ip->p = ip->begin = ip->line = xmalloc(INPUTSIZ);
+	ip->p[0] = '\0';
 	ip->nline = 0;
 	ip->next = input;
 	ip->fp = fp;
_AT_@ -89,7 +90,6 @@ ilex(char *fname)
 		}
 	}
 	allocinput(fname, fp);
-	*input->begin = '\0';
 	keywords(keys, NS_KEYWORD);
 }
 
-- 
2.8.1
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Sat May 07 2016 - 03:36:14 CEST