[tor-commits] [torsocks/master] Fix: lookup libc name and pass it to dlopen()

dgoulet at torproject.org dgoulet at torproject.org
Fri Apr 4 22:40:27 UTC 2014


commit 90cd878468554a5c9dd52718a74f401238120748
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Sat Nov 9 15:35:58 2013 -0500

    Fix: lookup libc name and pass it to dlopen()
    
    The configure process now looks up the libc file name on a per OS basis
    and this value is passed to dlopen() that handles the library lookup in
    the system like stated in dlopen(3).
    
    Fixes #12
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 configure.ac       |   41 +++++++++++++++--------------------------
 src/lib/torsocks.c |    6 +++---
 2 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index c02ffda..a6b7138 100644
--- a/configure.ac
+++ b/configure.ac
@@ -115,34 +115,23 @@ if test "x${enable_envconf}" = "x"; then
   AC_DEFINE([ALLOW_ENV_CONFIG],[],[Description])
 fi
 
-dnl Check that find is available, it should be somehere
-dnl in the path
-AC_CHECK_PROG(FIND, find, find)
-if test "${FIND}" = ""; then
-	AC_MSG_ERROR('find not found in path')
-fi
-
-dnl Find tail, it should always be somewhere in the path
-dnl but for safety's sake
-AC_CHECK_PROG(TAIL, tail, tail)
-if test "${TAIL}" = ""; then
-	AC_MSG_ERROR('tail not found in path')
-fi
-
 dnl Get libc full system path. Use prefix or some hardcoded standard
 dnl location on Unixish system.
-AC_MSG_CHECKING(location of libc.so)
-for DIR in "$prefix/lib" "$prefix/usr/lib" '/lib' '/usr/lib'; do
-	if test "${LIBC_PATH}" = ""; then
-		LIBC_PATH=`$FIND $DIR -name "libc.so.?" 2>/dev/null | $TAIL -1`
-	fi
-done
-AC_DEFINE_UNQUOTED([LIBC_PATH],["${LIBC_PATH}"],[Description])
-if test "${LIBC_PATH}" = ""; then
-	AC_MSG_ERROR("not found!")
-fi
-
-AC_MSG_RESULT($LIBC_PATH)
+AC_MSG_CHECKING(file name of the C library)
+AS_CASE([$host_os],
+	[darwin*], [libc_name="libSystem.dylib"],
+	[linux*],
+	[
+		libc_name=`ldd /bin/ls | grep libc | cut -d ' ' -f 1 | tr -d '\t'`
+		if test "${libc_name}" == ""; then
+			# Default libc on most system.
+			libc_name="libc.so.6"
+		fi
+	],
+	[libc_name="libc.so"]
+)
+AC_DEFINE_UNQUOTED([LIBC_NAME],["${libc_name}"], [Description])
+AC_MSG_RESULT($libc_name)
 
 ##############################################################################
 # 5. Determine how to preload libtorsocks.so on this system.
diff --git a/src/lib/torsocks.c b/src/lib/torsocks.c
index 93c2c35..332c561 100644
--- a/src/lib/torsocks.c
+++ b/src/lib/torsocks.c
@@ -123,9 +123,9 @@ static void init_libc_symbols(void)
 	void *libc_ptr;
 
 	dlerror();
-	libc_ptr = dlopen(LIBC_PATH, RTLD_LAZY);
+	libc_ptr = dlopen(LIBC_NAME, RTLD_LAZY);
 	if (!libc_ptr) {
-		ERR("Unable to dlopen() library " LIBC_PATH "(%s)", dlerror());
+		ERR("Unable to dlopen() library " LIBC_NAME "(%s)", dlerror());
 		goto error;
 	}
 
@@ -136,7 +136,7 @@ static void init_libc_symbols(void)
 	tsocks_libc_syscall = dlsym(libc_ptr, LIBC_SYSCALL_NAME_STR);
 	if (!tsocks_libc_connect || !tsocks_libc_close || !tsocks_libc_socket
 			|| !tsocks_libc_syscall) {
-		ERR("Unable to lookup symbols in " LIBC_PATH "(%s)", dlerror());
+		ERR("Unable to lookup symbols in " LIBC_NAME "(%s)", dlerror());
 		goto error;
 	}
 





More information about the tor-commits mailing list