summaryrefslogtreecommitdiffstats
path: root/applypatch/freecache.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-12-15 00:22:40 +0100
committerTao Bao <tbao@google.com>2018-12-17 19:07:27 +0100
commit7ebef8fd406ee4a2381fd6ab428b4392322f4390 (patch)
treebb57d4448c9a35b3cc578ae1aca5de0a69a03e0d /applypatch/freecache.cpp
parentMerge "Show wipe data confirmation text in recovery mode" (diff)
downloadandroid_bootable_recovery-7ebef8fd406ee4a2381fd6ab428b4392322f4390.tar
android_bootable_recovery-7ebef8fd406ee4a2381fd6ab428b4392322f4390.tar.gz
android_bootable_recovery-7ebef8fd406ee4a2381fd6ab428b4392322f4390.tar.bz2
android_bootable_recovery-7ebef8fd406ee4a2381fd6ab428b4392322f4390.tar.lz
android_bootable_recovery-7ebef8fd406ee4a2381fd6ab428b4392322f4390.tar.xz
android_bootable_recovery-7ebef8fd406ee4a2381fd6ab428b4392322f4390.tar.zst
android_bootable_recovery-7ebef8fd406ee4a2381fd6ab428b4392322f4390.zip
Diffstat (limited to '')
-rw-r--r--applypatch/freecache.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/applypatch/freecache.cpp b/applypatch/freecache.cpp
index e4878655e..3868ef230 100644
--- a/applypatch/freecache.cpp
+++ b/applypatch/freecache.cpp
@@ -141,8 +141,9 @@ static int64_t FreeSpaceForFile(const std::string& filename) {
return -1;
}
- int64_t free_space = static_cast<int64_t>(sf.f_bsize) * sf.f_bavail;
- if (sf.f_bsize == 0 || free_space / sf.f_bsize != sf.f_bavail) {
+ auto f_bsize = static_cast<int64_t>(sf.f_bsize);
+ auto free_space = sf.f_bsize * sf.f_bavail;
+ if (f_bsize == 0 || free_space / f_bsize != static_cast<int64_t>(sf.f_bavail)) {
LOG(ERROR) << "Invalid block size or overflow (sf.f_bsize " << sf.f_bsize << ", sf.f_bavail "
<< sf.f_bavail << ")";
return -1;
@@ -170,6 +171,13 @@ bool CheckAndFreeSpaceOnCache(size_t bytes) {
bool RemoveFilesInDirectory(size_t bytes_needed, const std::string& dirname,
const std::function<int64_t(const std::string&)>& space_checker) {
+ // The requested size cannot exceed max int64_t.
+ if (static_cast<uint64_t>(bytes_needed) >
+ static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
+ LOG(ERROR) << "Invalid arg of bytes_needed: " << bytes_needed;
+ return false;
+ }
+
struct stat st;
if (stat(dirname.c_str(), &st) == -1) {
PLOG(ERROR) << "Failed to stat " << dirname;
@@ -187,7 +195,7 @@ bool RemoveFilesInDirectory(size_t bytes_needed, const std::string& dirname,
}
LOG(INFO) << free_now << " bytes free on " << dirname << " (" << bytes_needed << " needed)";
- if (free_now >= bytes_needed) {
+ if (free_now >= static_cast<int64_t>(bytes_needed)) {
return true;
}
@@ -230,7 +238,7 @@ bool RemoveFilesInDirectory(size_t bytes_needed, const std::string& dirname,
return false;
}
LOG(INFO) << "Deleted " << file << "; now " << free_now << " bytes free";
- if (free_now >= bytes_needed) {
+ if (free_now >= static_cast<int64_t>(bytes_needed)) {
return true;
}
}