Message ID | 20181006192007.1945-1-tom@tromey.com |
---|---|
State | Under Review, archived |
Headers |
Received: (qmail 17067 invoked by alias); 6 Oct 2018 19:20:12 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 17053 invoked by uid 89); 6 Oct 2018 19:20:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=specially X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.152.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 06 Oct 2018 19:20:10 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 7D8D91840E for <gdb-patches@sourceware.org>; Sat, 6 Oct 2018 14:20:09 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 8s7VgUK0nRPoj8s7Vgn8CE; Sat, 06 Oct 2018 14:20:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=nX9YNtAUuLfwaK7WZWExkiCxoAS3HWvzasmkCBs8efM=; b=N0fDW4RLIYopjY4g5JKlWcE9OT 1z5OYKbseYbiCBzvsAEYJQ6cxDlBcBO1RWsa70NLvK6JhDSoXyHa4cCGn4utnCSUbfyWh2DuIStcf v7PhVGx1QyGqy3fHHVFdxZWGZ; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:44806 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from <tom@tromey.com>) id 1g8s7V-003Kms-9F; Sat, 06 Oct 2018 14:20:09 -0500 From: Tom Tromey <tom@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey <tom@tromey.com> Subject: [RFC] Avoid crash when calling warning too early Date: Sat, 6 Oct 2018 13:20:07 -0600 Message-Id: <20181006192007.1945-1-tom@tromey.com> |
Commit Message
Tom Tromey
Oct. 6, 2018, 7:20 p.m. UTC
I happened to notice that if you pass the name of an existing file (not a directory) as the argument to --data-directory, gdb will crash: $ ./gdb -nx --data-directory ./gdb ../../binutils-gdb/gdb/target.c:590:56: runtime error: member call on null pointer of type 'struct target_ops' This happens because warning ends up calling target_supports_terminal_ours, which calls current_top_target, which returns nullptr this early. This fixes the problem by handling this case specially in target_supports_terminal_ours. I wasn't sure whether this warranted a test case, hence the RFC. gdb/ChangeLog 2018-10-06 Tom Tromey <tom@tromey.com> * target.c (target_supports_terminal_ours): Handle case where current_top_target returns nullptr. --- gdb/ChangeLog | 5 +++++ gdb/target.c | 5 +++++ 2 files changed, 10 insertions(+)
Comments
On Saturday, October 06 2018, Tom Tromey wrote: > I happened to notice that if you pass the name of an existing file > (not a directory) as the argument to --data-directory, gdb will crash: > > $ ./gdb -nx --data-directory ./gdb > ../../binutils-gdb/gdb/target.c:590:56: runtime error: member call on null pointer of type 'struct target_ops' > > This happens because warning ends up calling > target_supports_terminal_ours, which calls current_top_target, which > returns nullptr this early. > > This fixes the problem by handling this case specially in > target_supports_terminal_ours. > > I wasn't sure whether this warranted a test case, hence the RFC. Thanks for the patch. I remember stumbling upon this issue a while ago, and had a similar patch to fix it, but I think I forgot to submit it. > gdb/ChangeLog > 2018-10-06 Tom Tromey <tom@tromey.com> > > * target.c (target_supports_terminal_ours): Handle case where > current_top_target returns nullptr. > --- > gdb/ChangeLog | 5 +++++ > gdb/target.c | 5 +++++ > 2 files changed, 10 insertions(+) > > diff --git a/gdb/target.c b/gdb/target.c > index 2d98954b54..a261155f29 100644 > --- a/gdb/target.c > +++ b/gdb/target.c > @@ -587,6 +587,11 @@ target_terminal::info (const char *arg, int from_tty) > int > target_supports_terminal_ours (void) > { > + /* This can be called before there is any target, so we must check > + for nullptr here. */ > + target_ops *top = current_top_target (); > + if (top == nullptr) > + return false; > return current_top_target ()->supports_terminal_ours (); > } The patch looks good to me. My only question is about whether we still require a newline between variable declarations and the rest of the code. I still follow this rule (because I think it improves code readability), but now with C++11 I'm not sure if it's still being enforced. Thanks,
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
Sergio> The patch looks good to me. My only question is about whether we still
Sergio> require a newline between variable declarations and the rest of the
Sergio> code. I still follow this rule (because I think it improves code
Sergio> readability), but now with C++11 I'm not sure if it's still being
Sergio> enforced.
I don't know, but I suppose so, and in any case I went ahead and added
it.
Tom
diff --git a/gdb/target.c b/gdb/target.c index 2d98954b54..a261155f29 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -587,6 +587,11 @@ target_terminal::info (const char *arg, int from_tty) int target_supports_terminal_ours (void) { + /* This can be called before there is any target, so we must check + for nullptr here. */ + target_ops *top = current_top_target (); + if (top == nullptr) + return false; return current_top_target ()->supports_terminal_ours (); }