>From 9d83c63ab6557d1a7effbcb6c88cac00bc507ef2 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <[email protected]>
Date: Fri, 6 May 2016 22:18:53 +0200
Subject: [PATCH] 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).
---
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
@@ -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);
}
--
2.8.1