From 5d0aaaf8e0b111e751bc5de8b70f0996927ddcac Mon Sep 17 00:00:00 2001 From: Qilin Tan Date: Thu, 2 Jan 2020 19:07:47 +0800 Subject: [PATCH] Fix the overflow issue in Checkpoint When the partition is f2fs and the OS is 32bit, the data.f_bavail and data.f_frsize are 32 bits in size. The product of them is also 32 bits in size. If the available size of storage is greater than 4G, the product may be greater than the unsigned long max value. If the product is overflow and less than 100M. The UDC feature will be disabled. There is also an overflow for std::strtoul when the variable content is a very big number(more the unsigned long max value). To avoid the overflow: 1. convert the variable data.f_bavvail to uint64_t and then compute the multiplication. 2. use std::strtoull replace to std::strtoul. Bug: 147118861 Change-Id: I60172ae4cb7c997e2ad4a36583be74736c25e565 --- Checkpoint.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Checkpoint.cpp b/Checkpoint.cpp index 88f7cad..df5fc88 100644 --- a/Checkpoint.cpp +++ b/Checkpoint.cpp @@ -320,13 +320,13 @@ static void cp_healthDaemon(std::string mnt_pnt, std::string blk_device, bool is uint64_t free_bytes = 0; if (is_fs_cp) { statvfs(mnt_pnt.c_str(), &data); - free_bytes = data.f_bavail * data.f_frsize; + free_bytes = ((uint64_t) data.f_bavail) * data.f_frsize; } else { std::string bow_device = fs_mgr_find_bow_device(blk_device); if (!bow_device.empty()) { std::string content; if (android::base::ReadFileToString(bow_device + "/bow/free", &content)) { - free_bytes = std::strtoul(content.c_str(), NULL, 10); + free_bytes = std::strtoull(content.c_str(), NULL, 10); } } }