Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 May 2002 07:25:35 +0900
From:      "Akinori MUSHA" <knu@iDaemons.org>
To:        audit@FreeBSD.org
Subject:   a tiny bug in ldd(1)'s shlib support
Message-ID:  <86adr2z7s0.wl@archon.local.idaemons.org>

next in thread | raw e-mail | index | archive | help
I found a tiny bug in ldd(1)'s shlib support.  If you do ldd against
libc.so, you'll get the following:

	knu@archon[2]% ldd /usr/lib/libc.so
	/usr/lib/libc.so:
	ldd: /usr/lib/libc.so: (null)
	/usr/lib/libc.so: exit status 1

This is because dlopen("/usr/lib/libc.so", RTLD_TRACE) returns without
an error as ldd(1) has already libc.so loaded.

The attached patch fixes the proglem by checking the return value of
dlopen() and exiting gracefully when no error has occurred:

	knu@archon[2]% ./ldd /usr/lib/libc.so
	/usr/lib/libc.so:

Can I commit this? (Or someone else please)

-- 
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"Somewhere out of a memory.. of lighted streets on quiet nights.."

Index: ldd.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/ldd/ldd.c,v
retrieving revision 1.31
diff -u -r1.31 ldd.c
--- ldd.c	28 Apr 2002 12:55:35 -0000	1.31
+++ ldd.c	14 May 2002 22:09:58 -0000
@@ -220,12 +220,13 @@
 			}
 			break;
 		case 0:
-			if (is_shlib == 0) {
+			if (is_shlib) {
+				if (dlopen(*argv, RTLD_TRACE))
+					_exit(0);	/* libc.so */
+				warnx("%s: %s", *argv, dlerror());
+			} else {
 				execl(*argv, *argv, (char *)NULL);
 				warn("%s", *argv);
-			} else {
-				dlopen(*argv, RTLD_TRACE);
-				warnx("%s: %s", *argv, dlerror());
 			}
 			_exit(1);
 		}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86adr2z7s0.wl>