If we do .export (all) and have any variables that involve :sh

we will hit an error (var is recursive) while trying to evaluate that.
Fix, and add a unit test for this.
This commit is contained in:
sjg 2010-04-21 04:25:27 +00:00
parent 3ae479ecfd
commit 862d4ff05d
3 changed files with 25 additions and 4 deletions

View File

@ -1,8 +1,20 @@
# $Id: export-all,v 1.1 2007/10/05 15:27:46 sjg Exp $
# $Id: export-all,v 1.2 2010/04/21 04:25:28 sjg Exp $
UT_OK=good
UT_F=fine
# the old way to do :tA
M_tAbad = C,.*,cd & \&\& 'pwd',:sh
# the new
M_tA = tA
here := ${.PARSEDIR}
# this will cause trouble (recursing if we let it)
UT_BADDIR = ${${here}/../${here:T}:L:${M_tAbad}:T}
# this will be ok
UT_OKDIR = ${${here}/../${here:T}:L:${M_tA}:T}
.export
.include "export"

View File

@ -33,12 +33,14 @@ UT_FU=fubar
UT_TEST=export
UT_ZOO=hoopie
UT_ALL=even this gets exported
UT_BADDIR=unit-tests
UT_DOLLAR=This is $UT_FU
UT_F=fine
UT_FOO=foobar is fubar
UT_FU=fubar
UT_NO=all
UT_OK=good
UT_OKDIR=unit-tests
UT_TEST=export-all
UT_ZOO=hoopie
At first, I am

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.157 2010/04/20 17:48:16 sjg Exp $ */
/* $NetBSD: var.c,v 1.158 2010/04/21 04:25:27 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: var.c,v 1.157 2010/04/20 17:48:16 sjg Exp $";
static char rcsid[] = "$NetBSD: var.c,v 1.158 2010/04/21 04:25:27 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: var.c,v 1.157 2010/04/20 17:48:16 sjg Exp $");
__RCSID("$NetBSD: var.c,v 1.158 2010/04/21 04:25:27 sjg Exp $");
#endif
#endif /* not lint */
#endif
@ -591,6 +591,13 @@ Var_Export1(const char *name, int parent)
v->flags |= (VAR_EXPORTED|VAR_REEXPORT);
return 1;
}
if (v->flags & VAR_IN_USE) {
/*
* We recursed while exporting in a child.
* This isn't going to end well, just skip it.
*/
return 0;
}
n = snprintf(tmp, sizeof(tmp), "${%s}", name);
if (n < (int)sizeof(tmp)) {
val = Var_Subst(NULL, tmp, VAR_GLOBAL, 0);