+//
+// For security, setuid programs ignore DYLD_* environment variables.
+// Additionally, the DYLD_* enviroment variables are removed
+// from the environment, so that any child processes don't see them.
+//
+static void pruneEnvironmentVariables(const char* envp[], const char*** applep)
+{
+ // delete all DYLD_* and LD_LIBRARY_PATH environment variables
+ int removedCount = 0;
+ const char** d = envp;
+ for(const char** s = envp; *s != NULL; s++) {
+ if ( (strncmp(*s, "DYLD_", 5) != 0) && (strncmp(*s, "LD_LIBRARY_PATH=", 16) != 0) ) {
+ *d++ = *s;
+ }
+ else {
+ ++removedCount;
+ }
+ }
+ *d++ = NULL;
+
+ // slide apple parameters
+ if ( removedCount > 0 ) {
+ *applep = d;
+ do {
+ *d = d[removedCount];
+ } while ( *d++ != NULL );
+ }
+
+ // setup DYLD_FALLBACK_FRAMEWORK_PATH, if not set in environment
+ if ( sEnv.DYLD_FALLBACK_FRAMEWORK_PATH == NULL ) {
+ const char** paths = sFrameworkFallbackPaths;
+ removePathWithPrefix(paths, "$HOME");
+ sEnv.DYLD_FALLBACK_FRAMEWORK_PATH = paths;
+ }
+
+ // default value for DYLD_FALLBACK_LIBRARY_PATH, if not set in environment
+ if ( sEnv.DYLD_FALLBACK_LIBRARY_PATH == NULL ) {
+ const char** paths = sLibraryFallbackPaths;
+ removePathWithPrefix(paths, "$HOME");
+ sEnv.DYLD_FALLBACK_LIBRARY_PATH = paths;
+ }
+}