From 90c5352a9746ee76d6219528e00ef5ef39d9dee4 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 21 Apr 2024 08:20:38 +0100 Subject: make: change how macros are read from the environment Originally there was no validation of macro names imported from the environment. However, process_macros() failed to account for the additional flag bit at this level. Thus, for example, SHELL was imported when it shouldn't have been. The problem the lack of validation was supposed to address was that of environment variables with invalid names, which the user may not have control over, causing a fatal error. As an alternative, silently ignore variables with invalid names on import from the environment. --- miscutils/make.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index 970919ddc..cc35d89eb 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -742,7 +742,10 @@ setmacro(const char *name, const char *val, int level) // If not defined, allocate space for new unsigned int bucket; - if (!valid && !is_valid_macro(name)) + if (!valid && !is_valid_macro(name)) { + // Silently drop invalid names from the environment + if (level == 3) + return; #if ENABLE_FEATURE_MAKE_POSIX error("invalid macro name '%s'%s", name, potentially_valid_macro(name) ? @@ -750,6 +753,7 @@ setmacro(const char *name, const char *val, int level) #else error("invalid macro name '%s'", name); #endif + } bucket = getbucket(name); mp = xzalloc(sizeof(struct macro)); @@ -2929,7 +2933,7 @@ int make_main(int argc UNUSED_PARAM, char **argv) } // Process macro definitions from the environment - process_macros(environ, 3 | M_VALID); + process_macros(environ, 3); // Update MAKEFLAGS and environment update_makeflags(); -- cgit v1.2.3-55-g6feb