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): fix undefined behavior when exporting ...



details:   https://anonhg.NetBSD.org/src/rev/08b35961d8bd
branches:  trunk
changeset: 947177:08b35961d8bd
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Dec 12 19:39:34 2020 +0000

description:
make(1): fix undefined behavior when exporting ${:U }

diffstat:

 usr.bin/make/var.c |  37 +++++++++++++++++++------------------
 1 files changed, 19 insertions(+), 18 deletions(-)

diffs (59 lines):

diff -r 43e6cffd65bc -r 08b35961d8bd usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Dec 12 19:31:17 2020 +0000
+++ b/usr.bin/make/var.c        Sat Dec 12 19:39:34 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.726 2020/12/12 19:31:17 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.727 2020/12/12 19:39:34 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.726 2020/12/12 19:31:17 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.727 2020/12/12 19:39:34 rillig Exp $");
 
 /* A string that may need to be freed after use. */
 typedef struct FStr {
@@ -674,23 +674,24 @@
 static void
 ExportVars(const char *varnames, Boolean isExport, VarExportFlags flags)
 {
-       if (varnames[0] != '\0') {
-               Words words = Str_Words(varnames, FALSE);
-
-               size_t i;
-               for (i = 0; i < words.len; i++) {
-                       const char *name = words.words[i];
-                       if (ExportVar(name, flags)) {
-                               if (var_exportedVars == VAR_EXPORTED_NONE)
-                                       var_exportedVars = VAR_EXPORTED_SOME;
-                               if (isExport && (flags & VAR_EXPORT_PARENT)) {
-                                       Var_Append(MAKE_EXPORTED, name,
-                                           VAR_GLOBAL);
-                               }
-                       }
-               }
-               Words_Free(words);
+       Words words = Str_Words(varnames, FALSE);
+       size_t i;
+
+       if (words.len == 1 && words.words[0][0] == '\0')
+               words.len = 0;
+
+       for (i = 0; i < words.len; i++) {
+               const char *varname = words.words[i];
+               if (!ExportVar(varname, flags))
+                       continue;
+
+               if (var_exportedVars == VAR_EXPORTED_NONE)
+                       var_exportedVars = VAR_EXPORTED_SOME;
+
+               if (isExport && (flags & VAR_EXPORT_PARENT))
+                       Var_Append(MAKE_EXPORTED, varname, VAR_GLOBAL);
        }
+       Words_Free(words);
 }
 
 /*



Home | Main Index | Thread Index | Old Index