Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1009719lqm; Thu, 2 May 2024 02:30:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeMIf7XNgcKaah0wx/tY0o9iWu6AA/s0QVberYOEZQdZlvHcH5qP81PQ35b71SijFWO4lNKnu7QauS7bX3IyM9Xsl4sTY+s1qJgYiT/w== X-Google-Smtp-Source: AGHT+IEvXqFdQA8/0i6mWjnjB1L6SwhHdxfbU88n+ww7cavQDk5kDFO/dp4TsCjxNeN4js0wQ686 X-Received: by 2002:a17:906:f893:b0:a58:7ea5:c49b with SMTP id lg19-20020a170906f89300b00a587ea5c49bmr1190034ejb.42.1714642238538; Thu, 02 May 2024 02:30:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714642238; cv=pass; d=google.com; s=arc-20160816; b=E0Jh1delaCwmmMp9yWbcljqtWcpMLAmRrv5nN5v3erYej+3VHpBf+AN/VCMtufWwDt aT4oD2uIEBdPqQHc5ayxWk9txHmBaDCoArJ3XWDxFgcO9Sxxm39RnRWk6K4/wNP7CqjB tZXksBmlW9erP/PyUaotIuvh50Rb2zdx66GHxjl+VHneUf1gAqTSOljeV5PT327FAl2z pPSuYB/UMSOye8pfQAJoxvGRqnatUEMzBSBFD5SdOvaOFMBlKTp71TksEk4TlU9dk5T8 bJxV6PlvkOGxubBhRxlo5L7/OoaN7IcOr0/7zk0loO1qRoFHaRv6LtmMgQDsWIcwFUu2 3sZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=g2LEDVE5qROl1QGeRYxEm7NhrBXqqzJn3HA30+RQCQs=; fh=wOO8JPQ6t4TCySIOKacDFNUopjhiDnauY7OnN7RIxik=; b=SMwua7ipNGQohLm2ke8SwyAjNqAwiE4acscOCBlOfqstMy4kwRTM0ivB4RkBLAphEr M8A8t4ayes3OWd+kRIYiwXN1IWJLdhD54ooEzlf3O/3MIlCQy8+Pnk1Uu6Ar+jjKzyB/ W5AqULb46irXt6zlPGhgnOaGz9ULBw6z0P1i0aOfD6lZbFQ9GBJASwiapJCOTnuy0b5i OCf+iv8/j/M7vRcOqnFovbPAVmVSkaOrBLTKcABMWeoJNOEa+Vx/mN/VozYSNBgvrteJ 4ZWOT5Il4McoRVq2DuKxVrcEwFZFhnJQuLuhpnitKFBhyCJqC+cq9PQFs/2pUaduJXM9 MgtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kGfegygy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166224-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166224-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x22-20020a1709064a9600b00a58bf25158asi306502eju.865.2024.05.02.02.30.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 02:30:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166224-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kGfegygy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166224-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166224-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 488AB1F278D1 for ; Thu, 2 May 2024 09:30:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B07FE55783; Thu, 2 May 2024 09:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kGfegygy" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D9BDC2C6BC; Thu, 2 May 2024 09:30:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714642224; cv=none; b=ktvFo4D1MEGLLoX295yz6qaGzVQVj4BUEXzVA0zaQRaTpb00nm5VKarrmmcmJfYUPbUKKx17njN49s/ouiIiIIqlqUZJ7FjQIUxVffw3ezLY42AP6FLbxj1vhsMR9nSoTfO8O+bW6rPg7kzreFcDrvB4cCgBjK/r5Ok87Qokzwg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714642224; c=relaxed/simple; bh=Qns0M3prwynpZkQZNCgqtHT45rA7WTncoO7uiBRtf3c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DPjpPIk3kQ0uSMLm+w8CShz6ArdB+haAgfzzhcGHrSncaKoqqGUWRM8Lzx6214+dNfqKZHxdVsWrbG5j0nwP2UGs/cjaokwHRX01RUZFlUKHunD2k/FQqfS3kXbw13Fir2wviF0wIQ+UHfByrdQIFwuLyll4kzG6j30jUAHpzsU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kGfegygy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74950C113CC; Thu, 2 May 2024 09:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714642224; bh=Qns0M3prwynpZkQZNCgqtHT45rA7WTncoO7uiBRtf3c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kGfegygyl/gPEHlP/t5eWjVLCfeyHxfqPhdCVmEJ6e4kl0VoqmS1s3paknd5LrASY U8jDEeKVcl68M5St/yCPcyApmrC4NYVnug4ivHpWwmV4gnG6wHEMPe0onv+ar0oAjD 7VFZ8e55Lw/ph4oXZ2thqsBAg+9cxngqt8+9tszOCVyJUqGvWRx7o3IRw5uqqmkKkT aUbtBlOo+X640h7z3/FRHfj2k/8HJ6ktWkCgEy5x0YK7vcO8iWVfSld6q12bdIweHL nI37CLfwuCXKLPEFRM9ewqkokz0BNp2WtfWV0xfoNVy2/ToHMkOqbRZzKsRMhRXkfe hiA2kX9+imivg== Date: Thu, 2 May 2024 10:30:19 +0100 From: Lee Jones To: Justin Stitt Cc: Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Kees Cook , Finn Thain Subject: Re: [PATCH v6] checkpatch: add check for snprintf to scnprintf Message-ID: <20240502093019.GH5338@google.com> References: <20240429-snprintf-checkpatch-v6-1-354c62c88290@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240429-snprintf-checkpatch-v6-1-354c62c88290@google.com> On Mon, 29 Apr 2024, Justin Stitt wrote: > I am going to quote Lee Jones who has been doing some snprintf -> > scnprintf refactorings: > > "There is a general misunderstanding amongst engineers that > {v}snprintf() returns the length of the data *actually* encoded into the > destination array. However, as per the C99 standard {v}snprintf() > really returns the length of the data that *would have been* written if > there were enough space for it. This misunderstanding has led to > buffer-overruns in the past. It's generally considered safer to use the > {v}scnprintf() variants in their place (or even sprintf() in simple > cases). So let's do that." > > To help prevent new instances of snprintf() from popping up, let's add a > check to checkpatch.pl. > > Suggested-by: Finn Thain > Signed-off-by: Justin Stitt > --- > Changes in v6: > - move capture group to only include symbol name (not spaces or paren) > - Link to v5: https://lore.kernel.org/r/20240422-snprintf-checkpatch-v5-1-f1e90bf7164e@google.com > > Changes in v5: > - use capture groups to let the user know which variation they used > - Link to v4: https://lore.kernel.org/r/20240408-snprintf-checkpatch-v4-1-8697c96ac94b@google.com > > Changes in v4: > - also check for vsnprintf variant (thanks Bill) > - Link to v3: https://lore.kernel.org/r/20240315-snprintf-checkpatch-v3-1-a451e7664306@google.com > > Changes in v3: > - fix indentation > - add reference link (https://github.com/KSPP/linux/issues/105) (thanks Joe) > - Link to v2: https://lore.kernel.org/r/20240221-snprintf-checkpatch-v2-1-9baeb59dae30@google.com > > Changes in v2: > - Had a vim moment and deleted a character before sending the patch. > - Replaced the character :) > - Link to v1: https://lore.kernel.org/r/20240221-snprintf-checkpatch-v1-1-3ac5025b5961@google.com > --- > From a discussion here [1]. > > [1]: https://lore.kernel.org/all/0f9c95f9-2c14-eee6-7faf-635880edcea4@linux-m68k.org/ > --- > scripts/checkpatch.pl | 6 ++++++ > 1 file changed, 6 insertions(+) Reviewed-by: Lee Jones -- Lee Jones [李琼斯]