ref: 08ddb8968c1ad3297d0a91efa646ba828fca6afe
parent: 6946e8df6d64cfd59a1c4ad9c22bbfb6914543d4
author: Hiltjo Posthuma <[email protected]>
date: Fri May 6 18:57:14 EDT 2016
[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).
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -30,6 +30,7 @@
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 @@
}
}
allocinput(fname, fp);
- *input->begin = '\0';
keywords(keys, NS_KEYWORD);
}