diff options
Diffstat (limited to 'parse.c')
| -rw-r--r-- | parse.c | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.218 2017/03/01 16:39:49 sjg Exp $ */ +/* $NetBSD: parse.c,v 1.225 2017/04/17 13:29:07 maya Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -69,14 +69,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: parse.c,v 1.218 2017/03/01 16:39:49 sjg Exp $"; +static char rcsid[] = "$NetBSD: parse.c,v 1.225 2017/04/17 13:29:07 maya Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; #else -__RCSID("$NetBSD: parse.c,v 1.218 2017/03/01 16:39:49 sjg Exp $"); +__RCSID("$NetBSD: parse.c,v 1.225 2017/04/17 13:29:07 maya Exp $"); #endif #endif /* not lint */ #endif @@ -130,6 +130,7 @@ __RCSID("$NetBSD: parse.c,v 1.218 2017/03/01 16:39:49 sjg Exp $"); #include <errno.h> #include <stdarg.h> #include <stdio.h> +#include <stdint.h> #include "make.h" #include "hash.h" @@ -539,7 +540,7 @@ loadfile(const char *path, int fd) if (lf->buf != MAP_FAILED) { /* succeeded */ if (lf->len == lf->maplen && lf->buf[lf->len - 1] != '\n') { - char *b = malloc(lf->len + 1); + char *b = bmake_malloc(lf->len + 1); b[lf->len] = '\n'; memcpy(b, lf->buf, lf->len++); munmap(lf->buf, lf->maplen); @@ -560,9 +561,15 @@ loadfile(const char *path, int fd) while (1) { assert(bufpos <= lf->len); if (bufpos == lf->len) { + if (lf->len > SIZE_MAX/2) { + errno = EFBIG; + Error("%s: file too large", path); + exit(1); + } lf->len *= 2; lf->buf = bmake_realloc(lf->buf, lf->len); } + assert(bufpos < lf->len); result = read(fd, lf->buf + bufpos, lf->len - bufpos); if (result < 0) { Error("%s: read error: %s", path, strerror(errno)); @@ -1099,15 +1106,15 @@ ParseDoSrc(int tOp, const char *src) *----------------------------------------------------------------------- */ static int -ParseFindMain(void *gnp, void *dummy) +ParseFindMain(void *gnp, void *dummy MAKE_ATTR_UNUSED) { GNode *gn = (GNode *)gnp; if ((gn->type & OP_NOTARGET) == 0) { mainNode = gn; Targ_SetMain(gn); - return (dummy ? 1 : 1); + return 1; } else { - return (dummy ? 0 : 0); + return 0; } } @@ -1145,10 +1152,10 @@ ParseAddDir(void *path, void *name) *----------------------------------------------------------------------- */ static int -ParseClearPath(void *path, void *dummy) +ParseClearPath(void *path, void *dummy MAKE_ATTR_UNUSED) { Dir_ClearPath((Lst) path); - return(dummy ? 0 : 0); + return 0; } /*- @@ -1685,10 +1692,12 @@ ParseDoDependency(char *line) } if (paths) { Lst_Destroy(paths, NULL); + paths = NULL; } if (specType == ExPath) Dir_SetPATH(); } else { + assert(paths == NULL); while (*line) { /* * The targets take real sources, so we must beware of archive @@ -1747,6 +1756,7 @@ ParseDoDependency(char *line) } out: + assert(paths == NULL); if (curTargs) Lst_Destroy(curTargs, NULL); } @@ -2550,7 +2560,7 @@ ParseTraditionalInclude(char *line) if (*file == '\0') { Parse_Error(PARSE_FATAL, "Filename missing from \"include\""); - return; + goto out; } for (file = all_files; !done; file = cp + 1) { @@ -2565,6 +2575,7 @@ ParseTraditionalInclude(char *line) Parse_include_file(file, FALSE, FALSE, silent); } +out: free(all_files); } #endif @@ -2615,6 +2626,7 @@ ParseGmakeExport(char *line) */ value = Var_Subst(NULL, value, VAR_CMD, VARF_WANTRES); setenv(variable, value, 1); + free(value); } #endif |
