From: Sidong Yang <realwakka@gmail.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH v2] btrfs-progs: cmds: Add subcommand that dumps file extents
Date: Wed, 14 Jul 2021 06:41:16 +0000 [thread overview]
Message-ID: <20210714064116.GA71963@realwakka> (raw)
In-Reply-To: <2c0484ff-670d-5a26-0a96-e396289a784f@gmx.com>
On Wed, Jul 14, 2021 at 06:16:08AM +0800, Qu Wenruo wrote:
>
>
> On 2021/7/14 上午12:54, Sidong Yang wrote:
> > 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.
>
> I guess Johannes means that, if we support more and more new compression
> algos, it can go beyond your original 16 bytes length for the
> compression algo name.
>
> While using strncpy, it will never go beyond COMPRESS_STR_LEN forever.
> (Although it will truncating the output, but that would be easier to
> spot the problem and then enlarge the macro)
Okay, I understood. I'll do this in next version.
Thanks,
Sidong
>
> Thanks,
> Qu
>
> >
> > Thanks,
> > Sidong
> >
> > >
> > > Thanks,
> > > Johannes
prev parent reply other threads:[~2021-07-14 6:41 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
2021-07-13 22:16 ` Qu Wenruo
2021-07-14 6:41 ` Sidong Yang [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=20210714064116.GA71963@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