OSDN Git Service

Fix ill-advised optimisation in $APPROOT environment lookup.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Mon, 20 Feb 2012 21:17:45 +0000 (21:17 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Mon, 20 Feb 2012 21:17:45 +0000 (21:17 +0000)
ChangeLog
src/rites.c

index 177b70f..a0eae0e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2012-02-20  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
+       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  <keithmarshall@users.sourceforge.net>
+
        Propagate sysroot path settings to scripts via the environment.
 
        * src/pkgbase.h (PKG_PUTENV_FLAGS_MASK): New constant; it maps...
index 03a26c0..dbfc403 100644 (file)
@@ -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;
 }