summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-12-18 05:14:43 +0100
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-12-18 05:14:43 +0100
commitfdb96a7e34c1f8e2c908bff96dc26ea04182ae0e (patch)
tree7476c222b110dbbf9a7f9c091e2e7da06539de87
parentSnap for 5184694 from 75f4073baf4b480f3d27da6b181e4aec6e30856d to qt-release (diff)
parent[automerger skipped] Merge "Add PrepareUpdateService." am: 2e33cbeb20 am: 1811a6b734 (diff)
downloadandroid_bootable_recovery-fdb96a7e34c1f8e2c908bff96dc26ea04182ae0e.tar
android_bootable_recovery-fdb96a7e34c1f8e2c908bff96dc26ea04182ae0e.tar.gz
android_bootable_recovery-fdb96a7e34c1f8e2c908bff96dc26ea04182ae0e.tar.bz2
android_bootable_recovery-fdb96a7e34c1f8e2c908bff96dc26ea04182ae0e.tar.lz
android_bootable_recovery-fdb96a7e34c1f8e2c908bff96dc26ea04182ae0e.tar.xz
android_bootable_recovery-fdb96a7e34c1f8e2c908bff96dc26ea04182ae0e.tar.zst
android_bootable_recovery-fdb96a7e34c1f8e2c908bff96dc26ea04182ae0e.zip
-rw-r--r--applypatch/freecache.cpp16
-rw-r--r--applypatch/imgpatch.cpp2
-rw-r--r--minui/events.cpp2
3 files changed, 14 insertions, 6 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;
}
}
diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp
index e6be39a2f..f4c33e5a3 100644
--- a/applypatch/imgpatch.cpp
+++ b/applypatch/imgpatch.cpp
@@ -54,7 +54,7 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_
const Value& patch, size_t patch_offset,
const char* deflate_header, SinkFn sink) {
size_t expected_target_length = static_cast<size_t>(Read8(deflate_header + 32));
- CHECK_GT(expected_target_length, 0);
+ CHECK_GT(expected_target_length, static_cast<size_t>(0));
int level = Read4(deflate_header + 40);
int method = Read4(deflate_header + 44);
int window_bits = Read4(deflate_header + 48);
diff --git a/minui/events.cpp b/minui/events.cpp
index 2894c3b6b..d94e97723 100644
--- a/minui/events.cpp
+++ b/minui/events.cpp
@@ -55,7 +55,7 @@ static bool test_bit(size_t bit, unsigned long* array) { // NOLINT
}
int ev_init(ev_callback input_cb, bool allow_touch_inputs) {
- g_epoll_fd = epoll_create(MAX_DEVICES + MAX_MISC_FDS);
+ g_epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (g_epoll_fd == -1) {
return -1;
}