Module Name: src Committed By: rillig Date: Sun Sep 6 19:24:12 UTC 2020
Modified Files: src/usr.bin/make: for.c Log Message: make(1): properly initialize For structure in For_Eval Initializing a Buffer or a strlist_t with zero-valued bytes only works by conincidence, but because it would be the correct way. In the code path "missing `in' in for", that zero-filled Buffer is freed using Buf_Destroy, which could have invoked undefined behavior. To generate a diff of this commit: cvs rdiff -u -r1.70 -r1.71 src/usr.bin/make/for.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/for.c diff -u src/usr.bin/make/for.c:1.70 src/usr.bin/make/for.c:1.71 --- src/usr.bin/make/for.c:1.70 Sun Sep 6 19:19:49 2020 +++ src/usr.bin/make/for.c Sun Sep 6 19:24:12 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: for.c,v 1.70 2020/09/06 19:19:49 rillig Exp $ */ +/* $NetBSD: for.c,v 1.71 2020/09/06 19:24:12 rillig Exp $ */ /* * Copyright (c) 1992, The Regents of the University of California. @@ -30,14 +30,14 @@ */ #ifndef MAKE_NATIVE -static char rcsid[] = "$NetBSD: for.c,v 1.70 2020/09/06 19:19:49 rillig Exp $"; +static char rcsid[] = "$NetBSD: for.c,v 1.71 2020/09/06 19:24:12 rillig Exp $"; #else #include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: for.c,v 1.70 2020/09/06 19:19:49 rillig Exp $"); +__RCSID("$NetBSD: for.c,v 1.71 2020/09/06 19:24:12 rillig Exp $"); #endif #endif /* not lint */ #endif @@ -152,7 +152,12 @@ For_Eval(char *line) */ new_for = bmake_malloc(sizeof *new_for); - memset(new_for, 0, sizeof *new_for); + Buf_Init(&new_for->buf, 0); + strlist_init(&new_for->vars); + strlist_init(&new_for->items); + new_for->parse_buf = NULL; + new_for->short_var = FALSE; + new_for->sub_next = 0; /* Grab the variables. Terminate on "in". */ for (;; ptr += len) { @@ -248,7 +253,6 @@ For_Eval(char *line) } } - Buf_Init(&new_for->buf, 0); accumFor = new_for; forLevel = 1; return 1;