From 42b93caf2ea8a4d8884eb0cd516e3e4b98554f7b Mon Sep 17 00:00:00 2001 From: Keith Marshall Date: Mon, 20 Feb 2012 21:17:45 +0000 Subject: [PATCH] Fix ill-advised optimisation in $APPROOT environment lookup. --- ChangeLog | 11 +++++++++++ src/rites.c | 13 +++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 177b70f..a0eae0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2012-02-20 Keith Marshall + Fix ill-advised optimisation in $APPROOT environment lookup. + + * src/rites.c (approot_path): Don't save result of getenv() lookup + across calls; the environment may have been moved in the interim, + making the original result invalid on any subsequent call. Also, + prefer MS-Windows style (with backslashes) for default. + (pkgLastRites): Report full path name for lastrites.exe, on execl() + failure, rather than only the path relative to $APPROOT. + +2012-02-20 Keith Marshall + Propagate sysroot path settings to scripts via the environment. * src/pkgbase.h (PKG_PUTENV_FLAGS_MASK): New constant; it maps... diff --git a/src/rites.c b/src/rites.c index 03a26c0..dbfc403 100644 --- a/src/rites.c +++ b/src/rites.c @@ -136,11 +136,16 @@ RITES_INLINE const char *approot_path( void ) /* Inline helper to identify the root directory path for the running * application, (which "mingw-get" passes through the APPROOT variable * in the process environment)... + * + * Caution: although this is called more than once, DO NOT attempt to + * optimise getenv() lookup by saving the returned pointer across calls; + * the environment block may have been moved between calls, which makes + * the pointer returned from a previous call potentially invalid! */ - static const char *approot = NULL; - return ((approot == NULL) && ((approot = getenv( "APPROOT" )) == NULL)) + char *approot; + return ((approot = getenv( "APPROOT" )) == NULL) - ? "c:/mingw/" /* default, for failed environment look-up */ + ? "c:\\mingw\\" /* default, for failed environment look-up */ : approot; /* normal return value */ } @@ -354,7 +359,7 @@ RITES_INLINE int pkgLastRites( int lock, const char *progname ) /* We should never get to here; if we do... * Diagnose a problem, and bail out. */ - fprintf( stderr, "%s: execl: ", progname ); perror( lastrites ); + fprintf( stderr, "%s: execl: ", progname ); perror( rites ); return EXIT_FATAL; } -- 2.11.0