NetBSD Problem Report #41760

From riastradh@joule.t.continuation.org  Tue Jul 21 18:55:21 2009
Return-Path: <riastradh@joule.t.continuation.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 9F91463B898
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 21 Jul 2009 18:55:21 +0000 (UTC)
Message-Id: <20090721185519.DC1671239@joule.t.continuation.org>
Date: Tue, 21 Jul 2009 18:55:19 +0000 (UTC)
From: Taylor R Campbell <campbell@mumble.net>
Reply-To: Taylor R Campbell <campbell@mumble.net>
To: gnats-bugs@gnats.NetBSD.org
Subject: dlclose and dlsym do not always prepare dlerror when they fail

>Number:         41760
>Category:       lib
>Synopsis:       dlclose and dlsym do not always prepare dlerror when they fail
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 21 19:00:00 +0000 2009
>Closed-Date:    Mon Oct 07 04:42:44 +0000 2013
>Last-Modified:  Mon Oct 07 04:42:44 +0000 2013
>Originator:     Taylor R Campbell <campbell@mumble.net>
>Release:        NetBSD 5.0_STABLE
>Organization:
>Environment:
System: NetBSD joule.t.continuation.org 5.0_STABLE NetBSD 5.0_STABLE (RIAGATE) #0: Sun Jun 14 17:49:06 EDT 2009 riastradh@Oberon.local:/Users/riastradh/os/netbsd/5/obj/sys/arch/i386/compile/RIAGATE i386
Architecture: i386
Machine: i386
>Description:

	If dlclose or dlsym fail, they should prepare dlerror to yield
	appropriate error messages, but they do not always do so.

>How-To-Repeat:

	Call dlclose or dlsym with a handle that is not known, such as
	NULL.  Observe that the call fails -- dlclose returns nonzero,
	or dlsym returns NULL.  Call dlerror to find the error string.
	Read a stale error string or NULL.

	Example:  The following program should exit with value 2 and
	print `dlclose: <message>', for some error message <message>.
	Instead, it prints two messages to standard error, of which
	one is from deep within ld.elf_so, and of which the other is
	`dlclose gave no error message'; then it exits with value 1.

#include <err.h>
#include <dlfcn.h>
#include <stdio.h>

int
main(int argc, char *argv[])
{
        if (dlclose(NULL) != 0)
        {
                const char *error = dlerror();
                if (error == NULL)
                        errx(1, "dlclose gave no error message");
                else
                        errx(2, "dlclose: %s", error);
        }

        errx(3, "dlclose succeeded");
}

>Fix:

	Apply the following patch to src/libexec/ld.elf_so/rtld.c:

===================================================================
RCS file: /cvsroot/src/libexec/ld.elf_so/rtld.c,v
retrieving revision 1.124
diff -p -u -r1.124 rtld.c
--- rtld.c	19 May 2009 20:44:52 -0000	1.124
+++ rtld.c	21 Jul 2009 18:51:53 -0000
@@ -591,7 +591,7 @@ _rtld_dlcheck(void *handle)
 			break;

 	if (obj == NULL || obj->dl_refcount == 0) {
-		xwarnx("Invalid shared object handle %p", handle);
+		_rtld_error("Invalid shared object handle %p", handle);
 		return NULL;
 	}
 	return obj;

>Release-Note:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41760 CVS commit: src/libexec/ld.elf_so
Date: Mon, 1 Oct 2012 03:03:46 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Oct  1 03:03:46 UTC 2012

 Modified Files:
 	src/libexec/ld.elf_so: rtld.c

 Log Message:
 On failure in _rtld_dlcheck, call _rtld_error, not xwarnx.

 Callers need not call _rtld_error themselves now.

 Fixes PR lib/41760.  Should add the test case from the PR too.


 To generate a diff of this commit:
 cvs rdiff -u -r1.158 -r1.159 src/libexec/ld.elf_so/rtld.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Jeff Rizzo" <riz@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41760 CVS commit: [netbsd-6] src/libexec/ld.elf_so
Date: Wed, 17 Oct 2012 22:36:59 +0000

 Module Name:	src
 Committed By:	riz
 Date:		Wed Oct 17 22:36:59 UTC 2012

 Modified Files:
 	src/libexec/ld.elf_so [netbsd-6]: rtld.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #605):
 	libexec/ld.elf_so/rtld.c: revision 1.159
 On failure in _rtld_dlcheck, call _rtld_error, not xwarnx.
 Callers need not call _rtld_error themselves now.
 Fixes PR lib/41760.  Should add the test case from the PR too.


 To generate a diff of this commit:
 cvs rdiff -u -r1.155 -r1.155.2.1 src/libexec/ld.elf_so/rtld.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: lib/41760: dlclose and dlsym do not always prepare dlerror when
 they fail
Date: Fri, 19 Oct 2012 15:02:16 +0000

 On Tue, Jul 21, 2009 at 07:00:00PM +0000, Taylor R Campbell wrote:
  > >Fix:
  > 
  > 	Apply the following patch to src/libexec/ld.elf_so/rtld.c:

 I see no pullup for netbsd-5 in the queue; should there be one, or is
 this PR done?

 -- 
 David A. Holland
 dholland@netbsd.org

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Mon, 07 Oct 2013 04:42:44 +0000
State-Changed-Why:
Fixed in head and -6 a year ago; if anyone wants it in -5 badly enough
to file the pullup, go ahead but otherwise I think we won't bother.


>Unformatted:
 Reply-To: riastradh
 X-send-pr-version: 3.95

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.