Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp871551rdb; Fri, 23 Feb 2024 02:46:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUYFmnKY5Tl3dvGThcHbXq4XqXrBxEjVXFiMmwvg/Y0/x9uMg8K2PXuHL8N6uwlo/kvHnge+xyIw/ie3hxzc/eHjB79Zx5hwweacKKqnw== X-Google-Smtp-Source: AGHT+IH2FFUget6PgRggbV8n/WZySRESpdKvKT8Ket8ofYB5nBmiprtkDQaONdaNPHVT2yVZTJ8j X-Received: by 2002:a05:6402:b33:b0:565:665b:9c82 with SMTP id bo19-20020a0564020b3300b00565665b9c82mr899995edb.8.1708685160474; Fri, 23 Feb 2024 02:46:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708685160; cv=pass; d=google.com; s=arc-20160816; b=o/TCr6Tra2ww5wpBSwPHcLuq9q8WFZriqrZ851nU3nqW1lwWIZeSXqzg6geQ8KLboR JI1gDqMX1mayG+kF9fuDTJpRlTt/ik91St+8smdlHmj2/2jBCsemXI85aTugnBoUKKai PIYUrsAb4Z1fE+u4sSQYwJG0vS8NG+gZFrSLSIViBdBuTnuKV/qJFYZoytgnNrcwX0TC IRYyeoCtxLRQuj180tJKnxQ//hAkiIwqc6xik1c1k8QL8prs2xnKThe6Tlqduwo4c5c4 XIRALikzMhDSta44kC7bVvpUYhwokBcWBZN3P2mwKx5ttdpDZRMjhFhLPHLcNh/8dOHQ TyEQ== 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=UfR8u5O59V5XFcujLgSl86T3E1iFwzMdwsPHzTC9hUU=; fh=YVYsuPtdZ4khmlTBEwKd63Ijwz2NQUigq/MCYasb7pk=; b=mzoIlwEzo8PGpKlJvVHUiE9Azuf0rcpo4WQ4uerANqP9ilLYYHYCpgC5GjAB8C+kUE VrIFa7s+gVAPfEmRcYHZ0yDT5UV2qDT81gLy46YbOwDeVOgNHK5XKvCTjAChCUZGm++g FeJscmEho6KOfoCwVkvUBWrV5/4c6aCBPW4BGHYbGBvE6RgCMg4WwdDGqqHL8MHQ83lz jDdDz/7mHt/gNzMFjmesKwjV/V60ham9c8/KZAUZ2ewgyQ7c56AhoYxiIDdBVuF6fbUo eRLICQrg/8ZroFs9WS+x+/Gy0kGQ7YtGW/oiALrhHCN+sfAZtWYXPF2em2AGaDKyWFO0 kRPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K6DU9Lko; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-78169-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78169-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b70-20020a509f4c000000b005657c7931dbsi213198edf.506.2024.02.23.02.46.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 02:46:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78169-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K6DU9Lko; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-78169-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78169-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 3C7CE1F21973 for ; Fri, 23 Feb 2024 10:46:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 106E678699; Fri, 23 Feb 2024 10:41:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="K6DU9Lko" 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 3647963111; Fri, 23 Feb 2024 10:41:26 +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=1708684887; cv=none; b=qwBOX3hs2IuuS9LplA5dy6gjnOyH17MTss3PRuGx9N85ZYA3/COQBrZCOQS5GMxA8PRlLJV99RDHnXYjd++iOwI8PP2xhABXeMu5t63W240aIluLsCiGy2LDivgh72D6kI0mrwQ5CrSUqoFse6Q8sp6emGuciurv85M9c5zCFkw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708684887; c=relaxed/simple; bh=yQ5gfwOefwOYR/TaCnNrogXr3ETb5Amk5wl97VmmEbA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qADtgk7NPSa7NwMVC84GhC/6iC4c0CNolQb+SHFhoNh15PiSnadNvuhxsj9WRtaggK6c5znrTPAGee9eLTVPOgcVBYIk2UaBGhlX9riI6Wld0YQzde5WfOJpevbS5n6Fr3ic9XPujAEPnQ+XV9l+8icKzUtGGQ+S07Tp0xBAvAQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K6DU9Lko; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBEA6C433F1; Fri, 23 Feb 2024 10:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708684886; bh=yQ5gfwOefwOYR/TaCnNrogXr3ETb5Amk5wl97VmmEbA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=K6DU9LkoALnHKFvraTWmnJPi71aDWQwUWdz9BFoY5zQg1PPgl79U5SA0buvUmM72M wwNXXpmQpzhl5Je1d9egRhXJ+9BRw0PXDt+MUDyfU3EIBw4U5BGEE/0aVPQupIcxi6 SeDch/AFzOd8U4QJyfzU+4pF744oUcOJPl9niqBTX7EOz6o3scAM/ktT5VkD2oBfq7 3HaR8aHcfVWKiYjRpKQa7KhNQeVEgOZDKPc1EHyS631wKkQ9A0k6XHhEDXsGtD6U3U 3MSZJVz3IsceBu3TiHlgyBJNWt1PwConf31kAUq0ysYpoz1XzQHZtQAI7i/aqksE0D Swe/EJ2/O1OfA== Date: Fri, 23 Feb 2024 10:41:21 +0000 From: Lee Jones To: David Laight Cc: 'Justin Stitt' , 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 v2] checkpatch: add check for snprintf to scnprintf Message-ID: <20240223104121.GQ10170@google.com> References: <20240221-snprintf-checkpatch-v2-1-9baeb59dae30@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: On Thu, 22 Feb 2024, David Laight wrote: > From: Justin Stitt > > Sent: 21 February 2024 22:12 > > > > 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." > > While generally true, there are places that really do want to > detect (and error) overflow. > That isn't possible with scnprintf(). > > I'm not sure what the solution is though. > Having a function that returns a negative value on overflow is also > likely to get misused. > seq_printf() (or whatever it is called) may let you check, > but it is hardly a cheap wrapper and a bit of a PITA to use. I agree. spprinf() was my favorite solution, but it seems that the lib string people don't like to accept new functionality, even if it's a clear improvement over the currently available solutions. [0] https://lore.kernel.org/all/20240130160953.766676-1-lee@kernel.org/ -- Lee Jones [李琼斯]