Skip to contentSkip to conversation

btrfs compression: check string length

PATCH In review Pavel Machek 2 participants 2 messages Sep 24, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs compression: check string length

AFAICT, with current code user could pass something like "lzox" and still get "lzo" compression. Check string lengths to prevent that.

fs/btrfs/compression.c +1 -1
index b05b361..1083ab4 100644
@@ -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))
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#1 lore raw
Quoted 10 lines · Pavel Machek

AFAICT, with current code user could pass something like "lzox" and still get "lzo" compression. Check string lengths to prevent that.

fs/btrfs/compression.c +0 -0
index b05b361..1083ab4 100644

fs/btrfs/compression.c bool btrfs_compress_is_valid_type(const char *str, size_t len) · line 55

Quoted 6 lines
fs/btrfs/compression.c +1 -1
@@ -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/[email protected]/msg88216.html

Quoted 3 lines
fs/btrfs/compression.c +0 -0
 		if (!strncmp(btrfs_compress_types[i], str, comp_len))