[hackers] [scc] [cc1] fix uninitialized value after include(), fixes test001 || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Sun, 8 May 2016 20:30:13 +0200 (CEST)

commit 96ab1dd52363dc766549b486e6603718783524f9
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
AuthorDate: Fri May 6 22:57:14 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Sat May 7 18:30:04 2016 +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).

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);
 }
 
Received on Sun May 08 2016 - 20:30:13 CEST

This archive was generated by hypermail 2.3.0 : Sun May 08 2016 - 20:36:17 CEST