From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id CA652384586D for ; Fri, 16 Dec 2022 13:38:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CA652384586D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 2BGDcICQ012228 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Dec 2022 08:38:22 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2BGDcICQ012228 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1671197903; bh=1L5hlANF7kYQ1FCnOmyz3yx3eZmmwQYcZXqIKXGkjSI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=sdrjqYcAjuLN/g01khPZLb8uwUEHMt2j67WXgK72BTnDMilLeGNtEd8KQF+1v7QXo YoOtmnb9B6b7QYqiQh1q1nVbGqUzqzM2yQ332itnaJ8R7adAbiRe5K2zJu1tiX/F0R rDfOUUi0qW1MUy3hqY4KaWE8DoApd1JyU4boBpLM= Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 05D801E112; Fri, 16 Dec 2022 08:38:17 -0500 (EST) Message-ID: <8a091e68-2609-b28d-3945-9b763ed9b6d0@polymtl.ca> Date: Fri, 16 Dec 2022 08:38:16 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH RESEND] gdb: remove static buffer in command_line_input Content-Language: en-US To: Pedro Alves , gdb-patches@sourceware.org Cc: Jan Vrany References: <20221215190625.758546-1-simon.marchi@polymtl.ca> <1e61d9cc-00e0-56d6-c232-96d465a78782@palves.net> From: Simon Marchi In-Reply-To: <1e61d9cc-00e0-56d6-c232-96d465a78782@palves.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 16 Dec 2022 13:38:18 +0000 X-Spam-Status: No, score=-3038.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 12/16/22 08:21, Pedro Alves wrote: > On 2022-12-15 7:06 p.m., Simon Marchi via Gdb-patches wrote: >> else >> { >> /* Copy whole line including terminating null, and we're >> done. */ >> - buffer_grow (cmd_line_buffer, rl, len + 1); >> - cmd = cmd_line_buffer->buffer; >> + cmd_line_buffer.append (rl, len + 1); >> + return true; > > std::string is guaranteed to be null terminated, but, it can also hold > \0 characters in the middle of the string. Isn't that > > cmd_line_buffer.append (rl, len + 1); > > ending up with an embedded \0 at the end of the string, with cmd_line_buffer.size() accounting for it? Argh, yes! I rewrote this patch from scratch multiple times until I got something satisfactory, and I know I changed that in a previous iteration, because I remember having that thought. Here's a patch to fix it: >From 8757d2ec9edf2ae0b77039ca0ecc9ca32fd87256 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 16 Dec 2022 08:34:56 -0500 Subject: [PATCH] gdb: don't copy final null character in command_line_append_input_line The modified std::string::append call currently copies the null character from the source string, leaving the std::string with a null character in its content, part of its size, in addition to the null character managed by the std::string itself We don't want to copy that null character, so remove that "+ 1". Change-Id: I412fe9bd6b08e7ce7604ef5d8038b62f1a784c9b --- gdb/event-top.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index fa86a89e4a19..fa9e1f3f6a73 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -640,7 +640,7 @@ command_line_append_input_line (std::string &cmd_line_buffer, const char *rl) { /* Copy whole line including terminating null, and we're done. */ - cmd_line_buffer.append (rl, len + 1); + cmd_line_buffer.append (rl, len); return true; } } base-commit: e60a615dde5d6674a6488b74afe807a775551407 -- 2.38.1