From xdsl0000474440@inode.at  Sun May 18 14:05:45 2014
Return-Path: <xdsl0000474440@inode.at>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 47402963
	for <freebsd-gnats-submit@freebsd.org>; Sun, 18 May 2014 14:05:45 +0000 (UTC)
Received: from b2bfep11.mx.upcmail.net (b2bfep11.mx.upcmail.net [62.179.121.56])
	by mx1.freebsd.org (Postfix) with ESMTP id A24202CFB
	for <freebsd-gnats-submit@freebsd.org>; Sun, 18 May 2014 14:05:43 +0000 (UTC)
Received: from edge11.upcmail.net ([192.168.13.81])
          by b2bfep11-int.chello.at
          (InterMail vM.8.01.05.11 201-2260-151-128-20120928) with ESMTP
          id <20140518140535.ZKXA25882.b2bfep11-int.chello.at@edge11.upcmail.net>
          for <freebsd-gnats-submit@freebsd.org>;
          Sun, 18 May 2014 16:05:35 +0200
Received: from iznogoud.viz ([91.119.56.164])
	by edge11.upcmail.net with edge
	id 3S5b1o00P3YbPKv0BS5b8G; Sun, 18 May 2014 16:05:35 +0200
Received: from wolfgang by iznogoud.viz with local (Exim 4.82 (FreeBSD))
	(envelope-from <wolfgang@iznogoud.viz>)
	id 1Wm1iY-0004f5-Sr; Sun, 18 May 2014 16:05:34 +0200
Message-Id: <85mwefi3m9.fsf@iznogoud.viz>
Date: Sat, 17 May 2014 15:33:40 +0200
From: Wolfgang Jenkner <wjenkner@inode.at>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Konstantin Belousov <kib@FreeBSD.org>
Subject: [patch] LD_LIBMAP has no effect on rtld
X-Send-Pr-Version: 3.114

>Number:         189911
>Category:       bin
>Synopsis:       [rtld] [patch] LD_LIBMAP has no effect on rtld
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 18 14:10:00 UTC 2014
>Closed-Date:    
>Last-Modified:  Thu May 22 03:45:48 UTC 2014
>Originator:     Wolfgang Jenkner
>Release:        FreeBSD 10.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD iznogoud.viz 10.0-STABLE FreeBSD 10.0-STABLE #0 r265095M: Tue Apr 29 20:38:44 CEST 2014 adm@iznogoud.viz:/usr/obj/usr/src/sys/IZNOGOUD-drm-update-38.a+ amd64

>Description:
Mapping a shared library to another - existing or not existing - library
via LD_LIBMAP, as described in rtld(1), has no effect (but it does work
when done in libmap.conf).
>How-To-Repeat:
$ LD_LIBMAP=libncurses.so.8=libncurses.so.5 ldd /bin/ls
/bin/ls:
	libutil.so.9 => /lib/libutil.so.9 (0x800823000)
	libncurses.so.8 => /lib/libncurses.so.8 (0x800a35000)
	libc.so.7 => /lib/libc.so.7 (0x800c82000)

On the other hand, with

$ cat /etc/libmap.conf
[ls]
libncurses.so.8 libncurses.so.5
$ 

we get

$ ldd /bin/ls
/bin/ls:
	libutil.so.9 => /lib/libutil.so.9 (0x800823000)
	libncurses.so.8 => /usr/local/lib/libncurses.so.5 (0x800a35000)
	libc.so.7 => /lib/libc.so.7 (0x800c53000)
	libtinfo.so.5.9 => /usr/local/lib/libtinfo.so.5.9 (0x800ffa000)
$ 

if  libncurses.so.5 from the devel/ncurses port exists.

Otherwise, we get

$ ldd /bin/ls
/bin/ls:
	libutil.so.9 => /lib/libutil.so.9 (0x800823000)
	libncurses.so.8 => not found (0)
	libc.so.7 => /lib/libc.so.7 (0x800a35000)
$ 

>Fix:
The following patch is against 10-STABLE, but should apply to HEAD as
well.

It seems that, due to an oversight in HEAD r232862, lmc_parse() was
passed wrong arguments in the libmap_override case.

Index: libexec/rtld-elf/libmap.c
===================================================================
--- libexec/rtld-elf/libmap.c	(revision 265095)
+++ libexec/rtld-elf/libmap.c	(working copy)
@@ -80,7 +80,7 @@
 
 	if (libmap_override) {
 		/*
-		 * Do some character replacement to make $LIBMAP look
+		 * Do some character replacement to make $LD_LIBMAP look
 		 * like a text file, then parse it.
 		 */
 		libmap_override = xstrdup(libmap_override);
@@ -94,8 +94,8 @@
 				break;
 			}
 		}
-		lmc_parse(p, strlen(p));
-		free(p);
+		lmc_parse(libmap_override, p - libmap_override);
+		free(libmap_override);
 	}
 
 	return (lm_count == 0);
>Release-Note:
>Audit-Trail:
>Unformatted:
