From patchwork Wed Jan 2 18:44:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 30943 Received: (qmail 68717 invoked by alias); 2 Jan 2019 18:44: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 68670 invoked by uid 89); 2 Jan 2019 18:44:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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=Hx-languages-length:1496 X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.193.12) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Jan 2019 18:44:18 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 6BD25400C812E for ; Wed, 2 Jan 2019 11:55:58 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id elV3g8qEIiQerelV3gBcTO; Wed, 02 Jan 2019 12:44:17 -0600 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=ilY9S50kGLBFm/BwfDp/42iOUA1P+BXhZQaZHnCVU0g=; b=GTIF3/149+N7JOiIRtdUae0oZf uWtGWyCnBjwPPzM9bTx1SHLR5bSCYq1iestMER06AdMKx7rL5umng+nO7m4hwgmEQonAGRD0DD2IR +aYfZZ48/nQfEFdUuGCRGM8+9; Received: from [50.236.237.38] (port=44440 helo=bapiya.TCHFunNetwork.pvt) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gelV3-004KKj-6x; Wed, 02 Jan 2019 12:44:17 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI] Use xstrdup in tui_set_source_content Date: Wed, 2 Jan 2019 11:44:14 -0700 Message-Id: <20190102184414.7084-1-tom@tromey.com> valgrind pointed out that the string copy in tui_set_source_content was not allocating space for the trailing \0: ==3941== Invalid write of size 1 ==3941== at 0x4C3239F: strcpy (vg_replace_strmem.c:512) ==3941== by 0x72036B: strcpy (string_fortified.h:90) ==3941== by 0x72036B: tui_set_source_content(symtab*, int, int) (tui-source.c:203) Looking closer, I don't think there's a need to check the line width here, so this patch changes it to use xstrdup. Tested by re-running the TUI under valgrind. There are still other valgrind reports from TUI code, but this one is gone. gdb/ChangeLog 2019-01-02 Tom Tromey * tui/tui-source.c (tui_set_source_content): Use xstrdup. --- gdb/ChangeLog | 4 ++++ gdb/tui/tui-source.c | 8 +------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 9c2a982cc0..ed9562a930 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -194,15 +194,9 @@ tui_set_source_content (struct symtab *s, xfree (TUI_SRC_WIN->generic.content[cur_line] ->which_element.source.line); - int alloc_len = text.size (); - if (alloc_len < line_width) - alloc_len = line_width + 1; TUI_SRC_WIN->generic.content[cur_line] ->which_element.source.line - = (char *) xmalloc (alloc_len); - strcpy (TUI_SRC_WIN->generic.content[cur_line] - ->which_element.source.line, - text.c_str ()); + = xstrdup (text.c_str ()); cur_line++; cur_line_no++;