From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10200 invoked by alias); 14 Mar 2011 10:38:01 -0000 Received: (qmail 10074 invoked by uid 22791); 14 Mar 2011 10:38:00 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Mar 2011 10:37:55 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2EAbr4L032498 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 14 Mar 2011 06:37:53 -0400 Received: from hase (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p2EAbqFm003994 for ; Mon, 14 Mar 2011 06:37:53 -0400 From: Andreas Schwab To: libc-hacker@sourceware.org Subject: [PATCH] Don't leave empty element in rpath when skipping an element References: X-Yow: Is this TERMINAL fun? Date: Wed, 30 Mar 2011 13:31:00 -0000 In-Reply-To: (Andreas Schwab's message of "Thu, 10 Mar 2011 14:17:57 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2011-03/txt/msg00006.txt.bz2 2011-03-14 Andreas Schwab * elf/dl-load.c (_dl_dst_substitute): When skipping the first rpath element also skip the following colon. (expand_dynamic_string_token): Add is_path parameter and pass down to DL_DST_REQUIRED and _dl_dst_substitute. (decompose_rpath): Call expand_dynamic_string_token with non-zero is_path. Ignore empty rpaths. (_dl_map_object_from_fd): Call expand_dynamic_string_token with zero is_path. --- elf/dl-load.c | 24 ++++++++++++++++++------ 1 files changed, 18 insertions(+), 6 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 1974ef5..ed3552f 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1,5 +1,5 @@ /* Map in a shared object's segments from the file. - Copyright (C) 1995-2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1995-2005, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -282,6 +282,10 @@ _dl_dst_substitute (struct link_map *l, const char *name, char *result, name += len; while (*name != '\0' && (!is_path || *name != ':')) ++name; + /* Also skip following colon if this is the first rpath + element, but keep an empty element at the end. */ + if (wp == result && is_path && *name == ':' && name[1] != '\0') + ++name; } else /* No DST we recognize. */ @@ -308,7 +312,7 @@ _dl_dst_substitute (struct link_map *l, const char *name, char *result, belonging to the map is loaded. In this case the path element containing $ORIGIN is left out. */ static char * -expand_dynamic_string_token (struct link_map *l, const char *s) +expand_dynamic_string_token (struct link_map *l, const char *s, int is_path) { /* We make two runs over the string. First we determine how large the resulting string is and then we copy it over. Since this is no @@ -319,7 +323,7 @@ expand_dynamic_string_token (struct link_map *l, const char *s) char *result; /* Determine the number of DST elements. */ - cnt = DL_DST_COUNT (s, 1); + cnt = DL_DST_COUNT (s, is_path); /* If we do not have to replace anything simply copy the string. */ if (__builtin_expect (cnt, 0) == 0) @@ -333,7 +337,7 @@ expand_dynamic_string_token (struct link_map *l, const char *s) if (result == NULL) return NULL; - return _dl_dst_substitute (l, s, result, 1); + return _dl_dst_substitute (l, s, result, is_path); } @@ -549,13 +553,21 @@ decompose_rpath (struct r_search_path_struct *sps, /* Make a writable copy. At the same time expand possible dynamic string tokens. */ - copy = expand_dynamic_string_token (l, rpath); + copy = expand_dynamic_string_token (l, rpath, 1); if (copy == NULL) { errstring = N_("cannot create RUNPATH/RPATH copy"); goto signal_error; } + /* Ignore empty rpaths. */ + if (*copy == 0) + { + free (copy); + sps->dirs = (char *) -1; + return false; + } + /* Count the number of necessary elements in the result array. */ nelems = 0; for (cp = copy; *cp != '\0'; ++cp) @@ -2177,7 +2189,7 @@ _dl_map_object (struct link_map *loader, const char *name, { /* The path may contain dynamic string tokens. */ realname = (loader - ? expand_dynamic_string_token (loader, name) + ? expand_dynamic_string_token (loader, name, 0) : local_strdup (name)); if (realname == NULL) fd = -1; -- 1.7.4 -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different."