scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 96ab1dd52363dc766549b486e6603718783524f9
parent 44f9e2933acbab1af87cd114eb43f5ead70409ff
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri,  6 May 2016 22:57:14 +0200

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

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).

Diffstat:
Mcc1/lex.c | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -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; @@ -89,7 +90,6 @@ ilex(char *fname) } } allocinput(fname, fp); - *input->begin = '\0'; keywords(keys, NS_KEYWORD); }