From: Sidong Yang <realwakka@gmail.com>
To: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>
Cc: linux-btrfs <linux-btrfs@vger.kernel.org>,
Qu Wenruo <quwenruo.btrfs@gmx.com>
Subject: Re: [PATCH v2] btrfs-progs: cmds: Add subcommand that dumps file extents
Date: Tue, 13 Jul 2021 16:54:44 +0000 [thread overview]
Message-ID: <20210713165444.GB71156@realwakka> (raw)
In-Reply-To: <PH0PR04MB7416299F37110AAD9FC7131E9B159@PH0PR04MB7416.namprd04.prod.outlook.com>
On Mon, Jul 12, 2021 at 06:52:28AM +0000, Johannes Thumshirn wrote:
Hi, Thanks for review!
> On 11/07/2021 18:10, Sidong Yang wrote:
> > +static void compress_type_to_str(u8 compress_type, char *ret)
> > +{
> > + switch (compress_type) {
> > + case BTRFS_COMPRESS_NONE:
> > + strcpy(ret, "none");
> > + break;
> > + case BTRFS_COMPRESS_ZLIB:
> > + strcpy(ret, "zlib");
> > + break;
> > + case BTRFS_COMPRESS_LZO:
> > + strcpy(ret, "lzo");
> > + break;
> > + case BTRFS_COMPRESS_ZSTD:
> > + strcpy(ret, "zstd");
> > + break;
> > + default:
> > + sprintf(ret, "UNKNOWN.%d", compress_type);
> > + }
> > +}
>
> [....]
> > + char compress_str[16];
>
> [...]
>
> > + compress_type_to_str(extent_item->compression, compress_str);
>
> While this looks safe at a first glance, can we change this to:
>
> #define COMPRESS_STR_LEN 5
>
> [...]
>
> switch (compress_type) {
> case BTRFS_COMPRESS_NONE:
> strncpy(ret, "none", COMPRESS_STR_LEN);
>
> [...]
>
> char compress_str[COMPRESS_STR_LEN];
>
> One day someone will factor out 'compress_type_to_str()' and make it public, read user
> supplied input and then it's a disaster waiting to happen.
This can be happen when @ret is too short? If it so, I think it also has
problem when @ret is shorter than COMPRESS_STR_LEN. I wonder that I
understood this problem you said.
Thanks,
Sidong
>
> Thanks,
> Johannes
next prev parent reply other threads:[~2021-07-13 16:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-11 16:10 [PATCH v2] btrfs-progs: cmds: Add subcommand that dumps file extents Sidong Yang
2021-07-12 1:16 ` Qu Wenruo
2021-07-12 6:40 ` Sidong Yang
2021-07-12 6:46 ` Qu Wenruo
2021-07-13 16:45 ` Sidong Yang
2021-07-12 6:52 ` Johannes Thumshirn
2021-07-13 16:54 ` Sidong Yang [this message]
2021-07-13 22:16 ` Qu Wenruo
2021-07-14 6:41 ` Sidong Yang
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=20210713165444.GB71156@realwakka \
--to=realwakka@gmail.com \
--cc=Johannes.Thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
/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