From 2612f9b1167e7c65f6d4015dee0b380cd91c4dc9 Mon Sep 17 00:00:00 2001 From: Alessio Balsini Date: Thu, 30 Apr 2020 20:48:48 +0100 Subject: [PATCH] snapshot_test: Fix overflow in statvfs arithmetics Operations on (unsigned long) f_bsize and f_bfree are correctly handled on 64 bit architectures, but when switching to 32 bit, the multiplication between the two could result in an overflow, causing the test to crash. Fix by using a uint64_t operand, hinting the compiler to handle the whole multiplication with 64 bit operands. Bug: 154355449 Bug: 148889015 Test: vts_libsnapshot_test (32 bit) Signed-off-by: Alessio Balsini Change-Id: Ief5c03ff7954c4a3e8597ef6e7df467f59428877 Merged-In: Ief5c03ff7954c4a3e8597ef6e7df467f59428877 --- fs_mgr/libsnapshot/test_helpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs_mgr/libsnapshot/test_helpers.cpp b/fs_mgr/libsnapshot/test_helpers.cpp index b036606e2..f82a60275 100644 --- a/fs_mgr/libsnapshot/test_helpers.cpp +++ b/fs_mgr/libsnapshot/test_helpers.cpp @@ -212,8 +212,8 @@ AssertionResult LowSpaceUserdata::ReadUserdataStats() { return AssertionFailure() << strerror(errno); } bsize_ = buf.f_bsize; - free_space_ = buf.f_bsize * buf.f_bfree; - available_space_ = buf.f_bsize * buf.f_bavail; + free_space_ = bsize_ * buf.f_bfree; + available_space_ = bsize_ * buf.f_bavail; return AssertionSuccess(); }