Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1429013lqe; Mon, 8 Apr 2024 08:38:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTGxUN37nT+dV7EbSK4H0PuKGntX83hdZfEn29KOaStSVfpLJD7ug+BmG4WYBvedy66rXEHlV8TnAMTegquBZ9m/rgAP23qY5XtWv/Ow== X-Google-Smtp-Source: AGHT+IHtWWvL2W9rAljxMruG6D/aqYy8CX3DTr5wyR1ry/DplRve8b0MGeX47VP8Q9IfPi09RVC2 X-Received: by 2002:a05:6358:4b0f:b0:186:235a:f32f with SMTP id kr15-20020a0563584b0f00b00186235af32fmr4270719rwc.30.1712590733164; Mon, 08 Apr 2024 08:38:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712590733; cv=pass; d=google.com; s=arc-20160816; b=vUs2ZYjf2V2QI6kJj6cobDuKt5CHR0lFf5otlvSyyzdQUrC106Hb4mhmjz9e+xibDY iNTZIap1OFjqNIQwjxOHgn7BGvKElVnUif7bKYKZN6xfwFuI1e/zdu/yU2tKZWgeqEYu sMcB/5rxxmv8vCQ2gtmlZ9i9j/wSO6asTLRfhgeiC5jZZAbKs2s96q4gYB55JUazwN6K q382PSWkka2BVwfm8JMjS9LV0MkbVaqEx6yVGzHAu/52VNU0AdO5DW2f/H1oVLq1YtkG YuJLYBbpvtG2aN6cr4TgJghhc4pBcBV2pT18GePftey71dSW2kqUCX2W/mgyroNma4Cp T2ZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:date:references:in-reply-to:message-id :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:feedback-id:dkim-signature:dkim-signature; bh=YkKaVO0IWtdVzEW+2plhy7Zqx1cBB2gS0olKYWW7LKQ=; fh=SQq6M7SSg4DQzzmlBR/EhxeVImMPRuModCFbx0tK9wg=; b=0ChvqkT6fHO9XEBy4/K/E4GukipABxKD532IM4NUSvUApussBu1SKEOdiDib7vwvGX Ns3MdX+gRuqK2WIzriCKmULc5aLli6N03whwT5BtXHIg2kEugDIKJ2odM00XAcwHOFzR 8b2gCMQFT+xVpJyHiHevxTDRZo0NM8uBJgeK0r/wjiZATmolUwHjKJsEIrzgcyY7df7S JxmH02Bemof0PIuKGjsRoqDIrEiFXiP+kBFKbMGOInZ/HBmIdqn2cyepAgPSFN1FgRsF LdQFCzWwRttpyC0gS0BdoYWjfxEFDg1/KzCmBFGgtKZcaJ+Gfw+AiRiIWBu6eFQrh01I bj4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm2 header.b=OC7odqCB; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=C47tX4Hg; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-135613-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i4-20020a63e444000000b005cdfa6ec001si6686299pgk.380.2024.04.08.08.38.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 08:38:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135613-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@arndb.de header.s=fm2 header.b=OC7odqCB; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=C47tX4Hg; arc=pass (i=1 spf=pass spfdomain=arndb.de dkim=pass dkdomain=arndb.de dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=arndb.de); spf=pass (google.com: domain of linux-kernel+bounces-135613-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=arndb.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CF66A287D9B for ; Mon, 8 Apr 2024 15:38:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96B181411E5; Mon, 8 Apr 2024 15:38:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b="OC7odqCB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="C47tX4Hg" Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B79F1411D9 for ; Mon, 8 Apr 2024 15:38:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712590727; cv=none; b=qZyHNa1IobfdxVzVmBRjcFOb5nOvQ6T1E0+jI4QmmPD4GofeNJdEEcNGtt/GUgrGBObBd6bCUDC1PWBSG8vNhkjzQoG1rLUGxAfvox5K9iTkAtShoocC0e3GrBDaBnsZAU0hx6514yI51fQ/CAB59I/UNCXWXVhP0D8neyvURDo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712590727; c=relaxed/simple; bh=jx3y8iEl1cgfFLMkQCZpKjXlaeo9PvLQB2ZrWLHu41M=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To:Cc: Subject:Content-Type; b=qpsXuiQQ0fUWxp4jTHYLGCqEUdDJLTrat8cxxOs6x0d83ILs8jOFcBPYnQ3xQY2qhMb1BeqiSwKc+HG+33LWmq0TCBbKM+7zZQBNmA75hDiC3AycKt4zQP0G2XoaNMPhWjxTJ96CNR8dm+zU6df3LJmJRZfmar8CdqHbu/u0oOE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de; spf=pass smtp.mailfrom=arndb.de; dkim=pass (2048-bit key) header.d=arndb.de header.i=@arndb.de header.b=OC7odqCB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=C47tX4Hg; arc=none smtp.client-ip=103.168.172.159 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arndb.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arndb.de Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A618311400D2; Mon, 8 Apr 2024 11:38:44 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute5.internal (MEProxy); Mon, 08 Apr 2024 11:38:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1712590724; x=1712677124; bh=YkKaVO0IWt dVzEW+2plhy7Zqx1cBB2gS0olKYWW7LKQ=; b=OC7odqCBVt/WFdzPITh/Mc/Eb/ QcatPQBwhPLVHSu3aq13S81qoRzyNcY3y9r6HWvGxxCJLLRC8ft+XOTIQAeP8eHM OeC4N3/W6VpuE3FzVQjPFHr5MNaFDMn0UxwcT8GbkWGRojg1wuL9+ia0ZImqhg0t ZNdMzp70HiXTzXe5GXPrXQHwS+8tHRe02jA/omtQks8l49cwTr2jhsE4kA+Xi4z/ kWcmHGbuV2dZQtPOvgxFe5UDH0poRZIwxHii4mHZbl/xIvseZngFLT2LeaqHms8x 9cfZLQ48gXQL3WDppq2ej/W6qzArURvr+Qn7zygJRUrWRgzj01+LfAVfXBsQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1712590724; x=1712677124; bh=YkKaVO0IWtdVzEW+2plhy7Zqx1cB B2gS0olKYWW7LKQ=; b=C47tX4HgZOnyz3n9E0BSTu0YOcvE5xeqeedN7xnmjxFF S12Xd416VXzjib/qo3mtV51HFcrtXfbIdlKHtMzrttJ1jLJBot4WfkRP/6eNXJxD KQBPckkBdH4Mend66QZBYMXsVfA/AowtM/T7LYc+AlSB9gDUfsbCWQhvtx7t18Sd N+fDiq2gKGXiN5fIpUK19oFCcBzjGRpeHFC/iSSbPhlt8eLa0ExO/M90y1iR4kH1 cNh9u0jpXJGkv2C0jJFlmcL/yauhAPemaNcKGsZIFOOQlPB2EtHDi8xhh4Z0Z2H5 wch3zpery2RnbZ16VTVYje7jCQvDNECO7NGBDu3Kyw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudegiedgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedftehr nhguuceuvghrghhmrghnnhdfuceorghrnhgusegrrhhnuggsrdguvgeqnecuggftrfgrth htvghrnhepffehueegteeihfegtefhjefgtdeugfegjeelheejueethfefgeeghfektdek teffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hrnhgusegrrhhnuggsrdguvg X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4CFD0B60089; Mon, 8 Apr 2024 11:38:44 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-368-gc733b1d8df-fm-20240402.001-gc733b1d8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <8b771062-7ce9-4b00-a488-91b231a1476e@app.fastmail.com> In-Reply-To: References: <20240328140512.4148825-1-arnd@kernel.org> <20240328140512.4148825-6-arnd@kernel.org> Date: Mon, 08 Apr 2024 17:38:24 +0200 From: "Arnd Bergmann" To: "Justin Stitt" , "Arnd Bergmann" Cc: linux-kernel@vger.kernel.org, "Andrew Morton" Subject: Re: [PATCH 05/11] test_hexdump: avoid string truncation warning Content-Type: text/plain On Fri, Mar 29, 2024, at 00:54, Justin Stitt wrote: > On Thu, Mar 28, 2024 at 03:04:49PM +0100, Arnd Bergmann wrote: >> From: Arnd Bergmann >> >> gcc can warn when a string is too long to fit into the strncpy() >> destination buffer, as it is here depending on the function >> arguments: >> >> inlined from 'test_hexdump_prepare_test.constprop' at /home/arnd/arm-soc/lib/test_hexdump.c:116:3: >> include/linux/fortify-string.h:108:33: error: '__builtin_strncpy' output truncated copying between 0 and 32 bytes from a string of length 32 [-Werror=stringop-truncation] >> 108 | #define __underlying_strncpy __builtin_strncpy >> | ^ >> include/linux/fortify-string.h:187:16: note: in expansion of macro '__underlying_strncpy' >> 187 | return __underlying_strncpy(p, q, size); >> | ^~~~~~~~~~~~~~~~~~~~ >> >> As far as I can tell, this is harmless here because the truncation is >> intentional, but using strscpy_pad() will avoid the warning since gcc >> does not (yet) know about it. >> > > We need to be careful. strscpy() or strscpy_pad() are not drop-in > replacements for strncpy(). [cut useful explanation] > It is possible I haven't fully considered the context of this change but > I think using strscpy_pad() will cause these tests to fail, if they > aren't failing I think we're getting lucky. You are correct. I do understand the nuances between strncpy() and strscpy(), but I failed to read this file properly. I'm still not entirely sure, but from my current reading, I think we can just use memcpy() to replace the strncpy() here, as both the input string data_b[] and the output real[TEST_HEXDUMP_BUF_SIZE] are sized to cover every possible 'len' value. This also follows what Linus did for the other original strncpy in b1286ed7158e ("test_hexdump: use memcpy instead of strncpy()"). I've reworked the patch based on that assumption now and rewritten the changelog text accordingly. Arnd