diff mbox series

btrfs compression: check string length

Message ID 20190924061452.GA31397@amd (mailing list archive)
State New, archived
Headers show
Series btrfs compression: check string length | expand

Commit Message

Pavel Machek Sept. 24, 2019, 6:14 a.m. UTC
AFAICT, with current code user could pass something like "lzox" and
still get "lzo" compression. Check string lengths to prevent that.

Signed-off-by: Pavel Machek <pavel@denx.de>

Comments

Nikolay Borisov Sept. 24, 2019, 7:01 a.m. UTC | #1
On 24.09.19 г. 9:14 ч., Pavel Machek wrote:
> AFAICT, with current code user could pass something like "lzox" and
> still get "lzo" compression. Check string lengths to prevent that.
> 
> Signed-off-by: Pavel Machek <pavel@denx.de>
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index b05b361..1083ab4 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -51,7 +51,7 @@ bool btrfs_compress_is_valid_type(const char *str, size_t len)
>  	for (i = 1; i < ARRAY_SIZE(btrfs_compress_types); i++) {
>  		size_t comp_len = strlen(btrfs_compress_types[i]);
>  
> -		if (len < comp_len)
> +		if (len != comp_len)
>  			continue;

It's like that so that we can support compression strings such as
zlib:9. In fact the initial version was written like you suggest:

https://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg88216.html

>  
>  		if (!strncmp(btrfs_compress_types[i], str, comp_len))
>
diff mbox series

Patch

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index b05b361..1083ab4 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -51,7 +51,7 @@  bool btrfs_compress_is_valid_type(const char *str, size_t len)
 	for (i = 1; i < ARRAY_SIZE(btrfs_compress_types); i++) {
 		size_t comp_len = strlen(btrfs_compress_types[i]);
 
-		if (len < comp_len)
+		if (len != comp_len)
 			continue;
 
 		if (!strncmp(btrfs_compress_types[i], str, comp_len))