From 37273b457033303b4d9ec00a1b3acda47f9189fe Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 1 Jun 2024 12:17:41 +0000 Subject: [PATCH] make: fix variable lifetime when initializing MAKE and .MAKE The pathbuf buffer is aliased by abspath, which later escapes the block where the buffer is declared. --- usr.bin/make/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index e657af670bc7..d586544642c0 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.620 2024/06/01 07:37:19 sjg Exp $ */ +/* $NetBSD: main.c,v 1.621 2024/06/01 12:17:41 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -111,7 +111,7 @@ #include "trace.h" /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: main.c,v 1.620 2024/06/01 07:37:19 sjg Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.621 2024/06/01 12:17:41 rillig Exp $"); #if defined(MAKE_NATIVE) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -1126,9 +1126,9 @@ static void InitVarMake(const char *argv0) { const char *make = argv0; + char pathbuf[MAXPATHLEN]; if (argv0[0] != '/' && strchr(argv0, '/') != NULL) { - char pathbuf[MAXPATHLEN]; const char *abspath = cached_realpath(argv0, pathbuf); struct stat st; if (abspath != NULL && abspath[0] == '/' &&