From patchwork Fri Feb 19 11:21:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 10919 Received: (qmail 42071 invoked by alias); 19 Feb 2016 11:21:25 -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 40681 invoked by uid 89); 19 Feb 2016 11:21:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Fri, 19 Feb 2016 11:21:23 +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 A1A758F4FD; Fri, 19 Feb 2016 11:21:21 +0000 (UTC) Received: from blade.nx (ovpn-116-96.ams2.redhat.com [10.36.116.96]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1JBLKfq002514; Fri, 19 Feb 2016 06:21:21 -0500 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id F1D1E264423; Fri, 19 Feb 2016 11:21:19 +0000 (GMT) From: Gary Benson To: gdb-patches@sourceware.org Cc: Pedro Alves , Luis Machado Subject: [PATCH v2] Fix logic in exec_file_locate_attach Date: Fri, 19 Feb 2016 11:21:19 +0000 Message-Id: <1455880879-310-1-git-send-email-gbenson@redhat.com> In-Reply-To: <20160219102447.GA29870@blade.nx> References: <20160219102447.GA29870@blade.nx> X-IsSubscribed: yes Hi all, This is an updated version of the patch I posted yesterday. It fails silently rather than throwing if the executable is not in the sysroot, which both fixes the sysroot-escape issue and results in a better GDB session for the user. Built and regtested on RHEL 6.6 x86_64. Luis, I think this patch will fix your connection drop without any further changes. Could you test it please? Thanks, Gary --- This commit fixes an error in exec_file_locate_attach where the main executable could be loaded from outside the sysroot if a nonempty, non-"target:" sysroot was set but the discovered executable filename did not exist in that sysroot and did exist on the main filesystem. gdb/ChangeLog: * exec.c (exec_file_locate_attach): Do not attempt to locate main executable locally if not found in sysroot. gdb/testsuite/ChangeLog: * gdb.base/attach-pie-noexec.exp: Do not expect an error message on attach. --- gdb/ChangeLog | 5 +++++ gdb/exec.c | 9 ++++++--- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.base/attach-pie-noexec.exp | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 0b8c077..90811c0 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -156,9 +156,12 @@ exec_file_locate_attach (int pid, int from_tty) /* If gdb_sysroot is not empty and the discovered filename is absolute then prefix the filename with gdb_sysroot. */ if (*gdb_sysroot != '\0' && IS_ABSOLUTE_PATH (exec_file)) - full_exec_path = exec_file_find (exec_file, NULL); - - if (full_exec_path == NULL) + { + full_exec_path = exec_file_find (exec_file, NULL); + if (full_exec_path == NULL) + return; + } + else { /* It's possible we don't have a full path, but rather just a filename. Some targets, such as HP-UX, don't provide the diff --git a/gdb/testsuite/gdb.base/attach-pie-noexec.exp b/gdb/testsuite/gdb.base/attach-pie-noexec.exp index f3e693a..1a51049 100644 --- a/gdb/testsuite/gdb.base/attach-pie-noexec.exp +++ b/gdb/testsuite/gdb.base/attach-pie-noexec.exp @@ -60,7 +60,7 @@ set testpid [spawn_id_get_pid $test_spawn_id] gdb_start file delete -- $binfile -gdb_test "attach $testpid" "Attaching to process $testpid\r\n.*: No such file or directory\\." "attach" +gdb_test "attach $testpid" "Attaching to process $testpid\r\n.*" "attach" gdb_test "set architecture $arch" "The target architecture is assumed to be $arch" gdb_test "info shared" "From\[ \t\]+To\[ \t\]+Syms Read\[ \t\]+Shared Object Library\r\n0x.*"