From patchwork Thu Jun 25 10:32:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 7346 Received: (qmail 4044 invoked by alias); 25 Jun 2015 10:32:38 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 4032 invoked by uid 89); 25 Jun 2015 10:32:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 25 Jun 2015 10:32:37 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 393D0B6E85 for ; Thu, 25 Jun 2015 10:32:36 +0000 (UTC) Received: from blade.nx (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5PAWZ4E003462 for ; Thu, 25 Jun 2015 06:32:35 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 0F56E2642D9 for ; Thu, 25 Jun 2015 11:32:35 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [OB PATCH] Correctly notice empty sysroots in solib_find_1 Date: Thu, 25 Jun 2015 11:32:34 +0100 Message-Id: <1435228354-9667-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes Hi all, Some parts of solib_find_1 should only operate if the sysroot is nonempty after processing, but the logic that checked this happened before trailing slashes were stripped so empty but non-NULL sysroots were possible. This commit moves the logic so it correctly notices all empty sysroots. Pushed as obvious. Cheers, Gary --- gdb/ChangeLog: * solib.c (solib_find_1): Set local variable sysroot to NULL if it is the empty string after trailing slashes have been stripped. --- gdb/ChangeLog | 5 +++++ gdb/solib.c | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/gdb/solib.c b/gdb/solib.c index ed1bc25..eb933c0 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -158,6 +158,7 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib) const char *fskind = effective_target_file_system_kind (); struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); char *sysroot = gdb_sysroot; + int prefix_len, orig_prefix_len; /* If the absolute prefix starts with "target:" but the filesystem accessed by the target_fileio_* methods is the local filesystem @@ -168,17 +169,16 @@ solib_find_1 (char *in_pathname, int *fd, int is_solib) if (is_target_filename (sysroot) && target_filesystem_is_local ()) sysroot += strlen (TARGET_SYSROOT_PREFIX); - if (*sysroot == '\0') - sysroot = NULL; - else - { - int prefix_len = strlen (sysroot); + /* Strip any trailing slashes from the absolute prefix. */ + prefix_len = orig_prefix_len = strlen (sysroot); - /* Remove trailing slashes from absolute prefix. */ - while (prefix_len > 0 - && IS_DIR_SEPARATOR (sysroot[prefix_len - 1])) - prefix_len--; + while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot[prefix_len - 1])) + prefix_len--; + if (prefix_len == 0) + sysroot = NULL; + else if (prefix_len != orig_prefix_len) + { sysroot = savestring (sysroot, prefix_len); make_cleanup (xfree, sysroot); }