Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): properly initialize For structure in F...



details:   https://anonhg.NetBSD.org/src/rev/00e2f111f161
branches:  trunk
changeset: 975795:00e2f111f161
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 06 19:24:12 2020 +0000

description:
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.

diffstat:

 usr.bin/make/for.c |  14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diffs (48 lines):

diff -r 862acd0f50e2 -r 00e2f111f161 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Sun Sep 06 19:19:49 2020 +0000
+++ b/usr.bin/make/for.c        Sun Sep 06 19:24:12 2020 +0000
@@ -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 @@
      */
 
     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 @@
        }
     }
 
-    Buf_Init(&new_for->buf, 0);
     accumFor = new_for;
     forLevel = 1;
     return 1;



Home | Main Index | Thread Index | Old Index