All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs compression: check string length
@ 2019-09-24  6:14 Pavel Machek
  2019-09-24  7:01 ` Nikolay Borisov
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Machek @ 2019-09-24  6:14 UTC (permalink / raw)
  To: clm, josef, dsterba, linux-btrfs, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 805 bytes --]

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;
 
 		if (!strncmp(btrfs_compress_types[i], str, comp_len))

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH] btrfs compression: check string length
  2019-09-24  6:14 [PATCH] btrfs compression: check string length Pavel Machek
@ 2019-09-24  7:01 ` Nikolay Borisov
  0 siblings, 0 replies; 2+ messages in thread
From: Nikolay Borisov @ 2019-09-24  7:01 UTC (permalink / raw)
  To: Pavel Machek, clm, David Sterba, josef, linux-btrfs, linux-kernel



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))
> 

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

end of thread, other threads:[~2019-09-24  7:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-24  6:14 [PATCH] btrfs compression: check string length Pavel Machek
2019-09-24  7:01 ` Nikolay Borisov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.