Skip to contentSkip to conversation

btrfs-progs: convert: Make ASSERT not truncate cctx.total_bytes value

PATCH In review Marcos Paulo de Souza 3 participants 3 messages Aug 26, 2020 – Aug 31, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: convert: Make ASSERT not truncate cctx.total_bytes value

From: Marcos Paulo de Souza <[email protected]>

Commit 670a19828ad ("btrfs-progs: convert: prevent 32bit overflow for cctx->total_bytes") added an assert to ensure that cctxx.total_bytes did not overflow, but this ASSERT calls assert_trace, which expects a long value.

By converting the u64 to long overflows in a 32bit machine, leading the assert_trace to be triggered since cctx.total_bytes turns to zero.

Fix this problem by comparing the cctx.total_bytes with zero when calling ASSERT.

---
 convert/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
convert/main.c +1 -1
index 5f8f64c5..378fd61a 100644
@@ -1158,7 +1158,7 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
 	if (ret)
 		goto fail;
 
-	ASSERT(cctx.total_bytes);
+	ASSERT(cctx.total_bytes != 0);
 	blocksize = cctx.blocksize;
 	total_bytes = (u64)blocksize * (u64)cctx.block_count;
 	if (blocksize < 4096) {
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

Commit 670a19828ad ("btrfs-progs: convert: prevent 32bit overflow for cctx->total_bytes") added an assert to ensure that cctxx.total_bytes did not overflow, but this ASSERT calls assert_trace, which expects a long value.

Oh, I forgot the type converting problem!

Quoted 8 lines

By converting the u64 to long overflows in a 32bit machine, leading the assert_trace to be triggered since cctx.total_bytes turns to zero.

Fix this problem by comparing the cctx.total_bytes with zero when calling ASSERT.

Awesome fix.

Thanks,
Qu

Quoted 18 lines
---
 convert/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
convert/main.c +1 -1
index 5f8f64c5..378fd61a 100644
@@ -1158,7 +1158,7 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
 	if (ret)
 		goto fail;
 
-	ASSERT(cctx.total_bytes);
+	ASSERT(cctx.total_bytes != 0);
 	blocksize = cctx.blocksize;
 	total_bytes = (u64)blocksize * (u64)cctx.block_count;
 	if (blocksize < 4096) {
#2 lore raw
In reply to Marcos Paulo de Souza
Quoted 7 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

Commit 670a19828ad ("btrfs-progs: convert: prevent 32bit overflow for cctx->total_bytes") added an assert to ensure that cctxx.total_bytes did not overflow, but this ASSERT calls assert_trace, which expects a long value.

Quoted 7 lines

By converting the u64 to long overflows in a 32bit machine, leading the assert_trace to be triggered since cctx.total_bytes turns to zero.

Fix this problem by comparing the cctx.total_bytes with zero when calling ASSERT.

Added to devel, thanks.