[tor-bugs] #5114 [Tor Client]: Environ not available on all versions of OS X, segfaults tor with obfsproxy

Tor Bug Tracker & Wiki torproject-admin at torproject.org
Mon Feb 13 18:47:42 UTC 2012


#5114: Environ not available on all versions of OS X, segfaults tor with obfsproxy
------------------------+---------------------------------------------------
 Reporter:  Sebastian   |          Owner:                    
     Type:  defect      |         Status:  new               
 Priority:  major       |      Milestone:  Tor: 0.2.3.x-final
Component:  Tor Client  |        Version:                    
 Keywords:              |         Parent:                    
   Points:              |   Actualpoints:                    
------------------------+---------------------------------------------------
 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));
 }}}

-- 
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/5114>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list