From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0S5bD40ng2oFLi0AWB0awg (envelope-from ) for ; Mon, 17 Aug 2026 11:23:57 -0400 Received: by simark.ca (Postfix, from userid 112) id 321631E0A3; Mon, 17 Aug 2026 11:23:57 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7C8801E033 for ; Mon, 17 Aug 2026 11:23:56 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 181094BA9018 for ; Mon, 17 Aug 2026 15:23:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 181094BA9018 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id CDF814BA79BE; Mon, 17 Aug 2026 15:18:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CDF814BA79BE Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CDF814BA79BE Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786979933; cv=none; b=UvPKWGgs6LSHVrdMfJheoUyX4HqdlyqBchgbJ+eSoUckQu8HOVb5v6m6B5mFX8zcHy5ZOu1NO5/Jjer629Y0iGqGQb4GzjhgrX08HhEA9FL82zhAVEyoFnrofKebnK464wI1KvXhtph7wqw4n5WRe7qjh4SczxOnI+dVcQZcmVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786979933; c=relaxed/simple; bh=xrgHdAXwZN9ZJtnf8b0gIeOIV+RFuPHYsgcEuqgAlTw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fLjlIVfnxXvxZqi7gvsEwPVVnxziqBwxAM17yIk9FTFVX+WUyC0Fym6RIFSvESZbewwL6xTQ0V8qetRQHJL5ZCGW6q4SIx3qKi3HUDdFxI5ntjxpsyuehqAeEnBcF9b7JBed5UU0IyiJxK5NnxNW//lD0EwzHSNcD+M2iCoNoUI= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CDF814BA79BE Received: by simark.ca (Postfix) id 6B2C21E168; Mon, 17 Aug 2026 11:18:53 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org, binutils@sourceware.org Cc: Simon Marchi Subject: [PATCH 11/13] gdb/remote-fileio: remove uses of sprintf Date: Mon, 17 Aug 2026 11:16:16 -0400 Message-ID: <20260817151646.152571-12-simon.marchi@efficios.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817151646.152571-1-simon.marchi@efficios.com> References: <20260817151646.152571-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org When building on macOS, I get some: /Users/smarchi/src/binutils-gdb/gdb/remote-fileio.c:264:3: error: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Werror,-Wdeprecated-declarations] 264 | sprintf (buf + strlen (buf), "%x", retcode); | ^ The reply built in remote_fileio_reply is made by appending to a fixed size buffer, using a mix of strcpy, strcat and sprintf. Replace them with the safer xsnprintf and xstrcpy. This way, every write is bounds checked. Change-Id: I8446a98be5c5fc0eda79ccbc4858d9dddaf2d4d5 --- gdb/remote-fileio.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c index a151161371da..297e3337e2fe 100644 --- a/gdb/remote-fileio.c +++ b/gdb/remote-fileio.c @@ -253,28 +253,37 @@ static void remote_fileio_reply (remote_target *remote, int retcode, int error) { char buf[32]; + char *p = buf; + char *const end = buf + sizeof (buf); bool ctrl_c = check_quit_flag (); - strcpy (buf, "F"); + p += xstrcpy (p, end - p, "F"); + if (retcode < 0) { - strcat (buf, "-"); + p += xstrcpy (p, end - p, "-"); retcode = -retcode; } - sprintf (buf + strlen (buf), "%x", retcode); + + p += xsnprintf (p, end - p, "%x", retcode); + if (error || ctrl_c) { if (error && ctrl_c) error = FILEIO_EINTR; + if (error < 0) { - strcat (buf, "-"); + p += xstrcpy (p, end - p, "-"); error = -error; } - sprintf (buf + strlen (buf), ",%x", error); + + p += xsnprintf (p, end - p, ",%x", error); + if (ctrl_c) - strcat (buf, ",C"); + p += xstrcpy (p, end - p, ",C"); } + quit_handler = remote_fileio_o_quit_handler; putpkt (remote, buf); } -- 2.55.0