Environ not available on all versions of OS X, segfaults tor with obfsproxy

I have a patch that fixes it for OS X. Obviously this isn't portable, but should give us the right idea.


diff --git a/src/or/transports.c b/src/or/transports.c
index d279d7a..3393850 100644
--- a/src/or/transports.c
+++ b/src/or/transports.c
@@ -91,6 +91,8 @@
 #include "util.h"
 #include "router.h"
 
+#include <crt_externs.h>
+
 #ifdef _WIN32
 static void set_managed_proxy_environment(LPVOID *envp,
                                           const managed_proxy_t *mp);
@@ -1076,8 +1078,6 @@ set_managed_proxy_environment(LPVOID *envp, const managed_proxy_t *mp)
 
 #else /* _WIN32 */
 
-extern char **environ;
-
 /** Prepare the environment <b>envp</b> of managed proxy <b>mp</b>.
  *  <b>envp</b> is allocated on the heap and should be freed by the
  *  caller after its use. */
@@ -1090,7 +1090,7 @@ set_managed_proxy_environment(char ***envp, const managed_proxy_t *mp)
   char *transports_to_launch=NULL;
   char *bindaddr=NULL;
   int environ_size=0;
-  char **environ_tmp = environ;
+  char **environ_tmp = *_NSGetEnviron();
 
   int n_envs = mp->is_server ? ENVIRON_SIZE_SERVER : ENVIRON_SIZE_CLIENT;
 
@@ -1098,7 +1098,7 @@ set_managed_proxy_environment(char ***envp, const managed_proxy_t *mp)
     environ_size++;
     environ_tmp++;
   }
-  environ_tmp = environ;
+  environ_tmp = *_NSGetEnviron();
 
   /* allocate enough space for our env. vars and a NULL pointer */
   *envp = tor_malloc(sizeof(char*)*(environ_size+n_envs+1));