From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19CA4C3F2CD for ; Mon, 23 Mar 2020 17:11:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E71F12074D for ; Mon, 23 Mar 2020 17:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727848AbgCWRLV (ORCPT ); Mon, 23 Mar 2020 13:11:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:58906 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727743AbgCWRLU (ORCPT ); Mon, 23 Mar 2020 13:11:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 921D2ADE2; Mon, 23 Mar 2020 17:11:19 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 1C730DA811; Mon, 23 Mar 2020 18:10:49 +0100 (CET) Date: Mon, 23 Mar 2020 18:10:48 +0100 From: David Sterba To: Takashi Iwai Cc: linux-btrfs@vger.kernel.org, Anand Jain , Chris Mason , Josef Bacik , David Sterba Subject: Re: [PATCH v2] btrfs: sysfs: Use scnprintf() instead of snprintf() Message-ID: <20200323171048.GL12659@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Takashi Iwai , linux-btrfs@vger.kernel.org, Anand Jain , Chris Mason , Josef Bacik , David Sterba References: <20200322090911.25296-1-tiwai@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200322090911.25296-1-tiwai@suse.de> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Sun, Mar 22, 2020 at 10:09:11AM +0100, Takashi Iwai wrote: > snprintf() is a hard-to-use function, and it's especially difficult to > use it properly for concatenating substrings in a buffer with a > limited size. Since snprintf() returns the would-be-output size, not > the actual size, the subsequent use of snprintf() may point to the > incorrect position easily. Also, returning the value from snprintf() > directly to sysfs show function would pass a bogus value that is > higher than the actually truncated string. > > That said, although the current code doesn't actually overflow the > buffer with PAGE_SIZE, it's a usage that shouldn't be done. Or it's > worse; this gives a wrong confidence as if it were doing safe > operations. > > This patch replaces such snprintf() calls with a safer version, > scnprintf(). It returns the actual output size, hence it's more > intuitive and the code does what's expected. Thanks, added to patch queue.