[4/4] btrfs: fix vanished compression property after failed set
diff mbox series

Message ID 20190403165134.12378-5-anand.jain@oracle.com
State New
Headers show
Series
  • property fixes and cleanups
Related show

Commit Message

Anand Jain April 3, 2019, 4:51 p.m. UTC
The compression property resets to NULL, instead of the old value if we
fail to set the new compression parameter.

btrfs prop get /btrfs compression
  compression=lzo
btrfs prop set /btrfs compression zli
  ERROR: failed to set compression for /btrfs: Invalid argument
btrfs prop get /btrfs compression

This is because the compression property ->validate() is successful for
'zli' as the strncmp() used the len passed from the userland.

Fix it by using the expected string length in strncmp().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
---
Please note:
This patch also fixes the bug that generation number gets updated when
property validation fails. As the reason its reason is weak validate(),
which lets the bad set pass untill ->apply().

 fs/btrfs/props.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
index b324a5fd7864..64b5f4695d4c 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -255,11 +255,11 @@  static int prop_compression_validate(const char *value, size_t len)
 	if (!value)
 		return 0;
 
-	if (!strncmp("lzo", value, len))
+	if (!strncmp("lzo", value, 3))
 		return 0;
-	else if (!strncmp("zlib", value, len))
+	else if (!strncmp("zlib", value, 4))
 		return 0;
-	else if (!strncmp("zstd", value, len))
+	else if (!strncmp("zstd", value, 4))
 		return 0;
 
 	return -EINVAL;