linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] btrfs: change set_level() to bound the level passed in
@ 2019-02-07 10:36 Dan Carpenter
  2019-02-07 15:40 ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2019-02-07 10:36 UTC (permalink / raw)
  To: dennis; +Cc: linux-btrfs

Hello Dennis Zhou,

The patch a67dc67a2cb8: "btrfs: change set_level() to bound the level
passed in" from Jan 28, 2019, leads to the following static checker
warning:

	fs/btrfs/compression.c:1576 btrfs_compress_str2level()
	error: uninitialized symbol 'level'.

fs/btrfs/compression.c
    1566 unsigned int btrfs_compress_str2level(unsigned int type, const char *str)
    1567 {
    1568 	unsigned int level;
    1569 	int ret;
    1570 
    1571 	if (!type)
    1572 		return 0;
    1573 
    1574 	if (str[0] == ':') {
    1575 		ret = kstrtouint(str + 1, 10, &level);
--> 1576 		if (ret)
    1577 			level = 0;

I feel like if the user gives bad input then we should just return an
error code instead of picking a level.

    1578 	}

level is not initialized if the first character is not ':'.

    1579 
    1580 	level = btrfs_compress_op[type]->set_level(level);
    1581 
    1582 	return level;
    1583 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [bug report] btrfs: change set_level() to bound the level passed in
  2019-02-07 10:36 [bug report] btrfs: change set_level() to bound the level passed in Dan Carpenter
@ 2019-02-07 15:40 ` David Sterba
  2019-02-07 15:43   ` Dennis Zhou
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2019-02-07 15:40 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: dennis, linux-btrfs

On Thu, Feb 07, 2019 at 01:36:47PM +0300, Dan Carpenter wrote:
> Hello Dennis Zhou,
> 
> The patch a67dc67a2cb8: "btrfs: change set_level() to bound the level
> passed in" from Jan 28, 2019, leads to the following static checker
> warning:
> 
> 	fs/btrfs/compression.c:1576 btrfs_compress_str2level()
> 	error: uninitialized symbol 'level'.
> 
> fs/btrfs/compression.c
>     1566 unsigned int btrfs_compress_str2level(unsigned int type, const char *str)
>     1567 {
>     1568 	unsigned int level;
>     1569 	int ret;
>     1570 
>     1571 	if (!type)
>     1572 		return 0;
>     1573 
>     1574 	if (str[0] == ':') {
>     1575 		ret = kstrtouint(str + 1, 10, &level);
> --> 1576 		if (ret)
>     1577 			level = 0;
> 
> I feel like if the user gives bad input then we should just return an
> error code instead of picking a level.

We've debated a bit and a warning with fallback to default is the
preferred option.
> 
>     1578 	}
> 
> level is not initialized if the first character is not ':'.

Right that's a bug, can be fixed by initializing level to 0, the
set_level() implementations will fall back to default then.

Thanks for the report.

> 
>     1579 
>     1580 	level = btrfs_compress_op[type]->set_level(level);
>     1581 
>     1582 	return level;
>     1583 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [bug report] btrfs: change set_level() to bound the level passed in
  2019-02-07 15:40 ` David Sterba
@ 2019-02-07 15:43   ` Dennis Zhou
  0 siblings, 0 replies; 3+ messages in thread
From: Dennis Zhou @ 2019-02-07 15:43 UTC (permalink / raw)
  To: David Sterba; +Cc: Dan Carpenter, dennis, linux-btrfs

On Thu, Feb 07, 2019 at 04:40:45PM +0100, David Sterba wrote:
> On Thu, Feb 07, 2019 at 01:36:47PM +0300, Dan Carpenter wrote:
> > Hello Dennis Zhou,
> > 
> > The patch a67dc67a2cb8: "btrfs: change set_level() to bound the level
> > passed in" from Jan 28, 2019, leads to the following static checker
> > warning:
> > 
> > 	fs/btrfs/compression.c:1576 btrfs_compress_str2level()
> > 	error: uninitialized symbol 'level'.
> > 
> > fs/btrfs/compression.c
> >     1566 unsigned int btrfs_compress_str2level(unsigned int type, const char *str)
> >     1567 {
> >     1568 	unsigned int level;
> >     1569 	int ret;
> >     1570 
> >     1571 	if (!type)
> >     1572 		return 0;
> >     1573 
> >     1574 	if (str[0] == ':') {
> >     1575 		ret = kstrtouint(str + 1, 10, &level);
> > --> 1576 		if (ret)
> >     1577 			level = 0;
> > 
> > I feel like if the user gives bad input then we should just return an
> > error code instead of picking a level.
> 
> We've debated a bit and a warning with fallback to default is the
> preferred option.
> > 
> >     1578 	}
> > 
> > level is not initialized if the first character is not ':'.
> 
> Right that's a bug, can be fixed by initializing level to 0, the
> set_level() implementations will fall back to default then.
> 
> Thanks for the report.
> 

Yeah that was a blunder on my part. I fixed it in v2 of 0009 in that
series:
https://lore.kernel.org/lkml/20190206164854.GB73401@dennisz-mbp.dhcp.thefacebook.com/

> > 
> >     1579 
> >     1580 	level = btrfs_compress_op[type]->set_level(level);
> >     1581 
> >     1582 	return level;
> >     1583 }

Thanks,
Dennis

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-07 15:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-07 10:36 [bug report] btrfs: change set_level() to bound the level passed in Dan Carpenter
2019-02-07 15:40 ` David Sterba
2019-02-07 15:43   ` Dennis Zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).