From: David Sterba <dsterba@suse.cz>
To: Takashi Iwai <tiwai@suse.de>
Cc: linux-btrfs@vger.kernel.org, Anand Jain <anand.jain@oracle.com>,
Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>
Subject: Re: [PATCH v2] btrfs: sysfs: Use scnprintf() instead of snprintf()
Date: Mon, 23 Mar 2020 18:10:48 +0100 [thread overview]
Message-ID: <20200323171048.GL12659@twin.jikos.cz> (raw)
In-Reply-To: <20200322090911.25296-1-tiwai@suse.de>
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.
prev parent reply other threads:[~2020-03-23 17:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-22 9:09 [PATCH v2] btrfs: sysfs: Use scnprintf() instead of snprintf() Takashi Iwai
2020-03-23 17:10 ` David Sterba [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200323171048.GL12659@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=anand.jain@oracle.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox