btrfs-progs: convert: Make ASSERT not truncate cctx.total_bytes value
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
@@ -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
Quoted 6 lines · Marcos Paulo de Souza
From: Marcos Paulo de Souza <[email protected]>
Commit
670a19828ad("btrfs-progs: convert: prevent 32bit overflow forcctx->total_bytes") added an assert to ensure that cctxx.total_bytes did not overflow, but this ASSERT callsassert_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_traceto be triggered since cctx.total_bytes turns to zero.Fix this problem by comparing the cctx.total_bytes with zero when calling ASSERT.
Signed-off-by Marcos Paulo de Souza <[email protected]>
Awesome fix.
Thanks,
Qu
Quoted 18 lines
--- convert/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)convert/main.c +1
-1@@ -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 ) {
Quoted 7 lines · Marcos Paulo de Souza
From: Marcos Paulo de Souza <[email protected]>
Commit
670a19828ad("btrfs-progs: convert: prevent 32bit overflow forcctx->total_bytes") added an assert to ensure that cctxx.total_bytes did not overflow, but this ASSERT callsassert_trace, which expects a long value.
Quoted 7 lines
By converting the u64 to long overflows in a 32bit machine, leading the
assert_traceto be triggered since cctx.total_bytes turns to zero.Fix this problem by comparing the cctx.total_bytes with zero when calling ASSERT.
Signed-off-by Marcos Paulo de Souza <[email protected]>
Added to devel, thanks.