Index: lib/sanitizer_common/sanitizer_linux.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux.cc +++ lib/sanitizer_common/sanitizer_linux.cc @@ -56,6 +56,7 @@ // FreeBSD 9.2 and 10.0. #include } +extern char **environ; #endif // SANITIZER_FREEBSD #if !SANITIZER_ANDROID @@ -315,9 +316,17 @@ return (u64)tv.tv_sec * 1000*1000*1000 + tv.tv_usec * 1000; } -// Like getenv, but reads env directly from /proc and does not use libc. -// This function should be called first inside __asan_init. +// Like getenv, but reads env directly from /proc (on Linux) or parses the +// 'environ' array (on FreeBSD) and does not use libc. This function should be +// called first inside __asan_init. const char *GetEnv(const char *name) { +#if SANITIZER_FREEBSD + uptr NameLen = internal_strlen(name); + for (char **Env = ::environ; *Env != NULL; Env++) { + if (internal_strncmp(*Env, name, NameLen) == 0 && (*Env)[NameLen] == '=') + return (*Env) + NameLen + 1; + } +#else static char *environ; static uptr len; static bool inited; @@ -340,6 +349,7 @@ return p + namelen + 1; // point after = p = endp + 1; } +#endif return 0; // Not found. }