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
This commit is contained in:
parent
f9510e3262
commit
5d0aaaf8e0
1 changed files with 2 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue