Skip to content

Instantly share code, notes, and snippets.

@amotl
Created February 12, 2012 23:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amotl/1811671 to your computer and use it in GitHub Desktop.
Save amotl/1811671 to your computer and use it in GitHub Desktop.
memmem-fix for tor-0.2.3.12-alpha on mac os x < 10.7

Problem

./tor --version
Tor version 0.2.3.11-alpha-dev (git-5d763b3d0bf8898e).

Tor compiled on Mac OS X 10.7 (Lion), but running on 10.6.8 (Snow Leopard):

./tor
dyld: lazy symbol binding failed: Symbol not found: _memmem  Referenced from: /Applications/TorBrowser.app/Contents/MacOS/./tor
  Expected in: /usr/lib/libSystem.B.dylib

dyld: Symbol not found: _memmem
  Referenced from: /Applications/TorBrowser.app/Contents/MacOS/./tor
  Expected in: /usr/lib/libSystem.B.dylib

Analysis

Tor compiled on Mac OS X 10.7 (Lion) [from tor-obfsproxy-browser-bundle-2.3.10]:

otool -I -v tor | grep memmem
0x000000010019557a 17226 _memmem
0x000000010023b3a0 17226 _memmem

Tor ./configure on Mac OS X 10.6.8 (Snow Leopard):

checking for memmem... no

Tor compiled on Mac OS X 10.6.8 (Snow Leopard):

otool -I -v tor | grep memmem

Proposal

Add the comfort to make releases compatible with lower Mac OS X versions, even when building with Lion. Won't need a separate build slave then. Drawback would be not having the (faster) glibc memmem implementation, but this should be a non-issue from the perspective of a quick-fix for enhancing the out-of-box experience. :

git clone git://gitweb.torproject.org/tor.git
cd tor
wget --no-check-certificate https://raw.github.com/gist/1811671/memmem-fix-2.patch
patch -p1 < memmem-fix-2.patch
./autogen.sh
./configure
make
otool -I -v src/or/tor | grep memmem

Note

No reference to memmem should exist.

References

diff --git a/ChangeLog b/ChangeLog
index 755ab0d..688946f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -33,6 +33,9 @@ Changes in version 0.2.3.12-alpha - 2012-02-??
- Use the correct CVE number for CVE-2011-4576 in our comments and
log messages. Found by "fermenthor". Resolves bug 5066; fix on
0.2.3.11-alpha.
+ - Fix "dyld: lazy symbol binding failed: Symbol not found: _memmem"
+ on Mac OS X Snow Leopard (<10.7) when built with Lion (10.7).
+ Resolves bug YYYY.
o Code simplifications and refactoring:
- Use the _WIN32 macro throughout our code to detect Windows.
diff --git a/src/common/compat.c b/src/common/compat.c
index 64c0668..e3c067d 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -111,6 +111,11 @@
#include "strlcat.c"
#endif
+/* XXXXYYY Mac OS X < 10.7.x has no "memmem" */
+#if (!defined(__GNUC__) || __GNUC__ >= 2) && !defined(__APPLE__)
+#define USE_MEMMEM
+#endif
+
/** As open(path, flags, mode), but return an fd with the close-on-exec mode
* set. */
int
@@ -458,7 +463,7 @@ const void *
tor_memmem(const void *_haystack, size_t hlen,
const void *_needle, size_t nlen)
{
-#if defined(HAVE_MEMMEM) && (!defined(__GNUC__) || __GNUC__ >= 2)
+#if defined(HAVE_MEMMEM) && defined(USE_MEMMEM)
tor_assert(nlen);
return memmem(_haystack, hlen, _needle, nlen);
#else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment