summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhishek Arpure <aarpure@codeaurora.org>2017-09-29 12:59:38 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-09-29 12:59:38 +0200
commit5b1975b6ccb17fc77ecc3a771655ae1040ae1141 (patch)
treef3e3409ebacd894676f70b34f1938a54aff8212a
parentMerge "roots: volume_for_path() parses and tries prefixes." am: 3a1587f655 am: fdbe272dc0 am: 3421fa1815 (diff)
parentMerge "Integer overflow observed while formatting volume" am: 846f307c6f am: 4a20e8b68f (diff)
downloadandroid_bootable_recovery-5b1975b6ccb17fc77ecc3a771655ae1040ae1141.tar
android_bootable_recovery-5b1975b6ccb17fc77ecc3a771655ae1040ae1141.tar.gz
android_bootable_recovery-5b1975b6ccb17fc77ecc3a771655ae1040ae1141.tar.bz2
android_bootable_recovery-5b1975b6ccb17fc77ecc3a771655ae1040ae1141.tar.lz
android_bootable_recovery-5b1975b6ccb17fc77ecc3a771655ae1040ae1141.tar.xz
android_bootable_recovery-5b1975b6ccb17fc77ecc3a771655ae1040ae1141.tar.zst
android_bootable_recovery-5b1975b6ccb17fc77ecc3a771655ae1040ae1141.zip
Diffstat (limited to '')
-rw-r--r--roots.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/roots.cpp b/roots.cpp
index 835a1dda0..7d7d1bdc7 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -18,6 +18,7 @@
#include <ctype.h>
#include <fcntl.h>
+#include <stdint.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/stat.h>
@@ -197,16 +198,22 @@ static int exec_cmd(const std::vector<std::string>& args) {
return WEXITSTATUS(status);
}
-static ssize_t get_file_size(int fd, uint64_t reserve_len) {
+static int64_t get_file_size(int fd, uint64_t reserve_len) {
struct stat buf;
int ret = fstat(fd, &buf);
if (ret) return 0;
- ssize_t computed_size;
+ int64_t computed_size;
if (S_ISREG(buf.st_mode)) {
computed_size = buf.st_size - reserve_len;
} else if (S_ISBLK(buf.st_mode)) {
- computed_size = get_block_device_size(fd) - reserve_len;
+ uint64_t block_device_size = get_block_device_size(fd);
+ if (block_device_size < reserve_len ||
+ block_device_size > std::numeric_limits<int64_t>::max()) {
+ computed_size = 0;
+ } else {
+ computed_size = block_device_size - reserve_len;
+ }
} else {
computed_size = 0;
}
@@ -250,13 +257,13 @@ int format_volume(const char* volume, const char* directory) {
close(fd);
}
- ssize_t length = 0;
+ int64_t length = 0;
if (v->length != 0) {
length = v->length;
} else if (v->key_loc != nullptr && strcmp(v->key_loc, "footer") == 0) {
android::base::unique_fd fd(open(v->blk_device, O_RDONLY));
if (fd == -1) {
- PLOG(ERROR) << "get_file_size: failed to open " << v->blk_device;
+ PLOG(ERROR) << "format_volume: failed to open " << v->blk_device;
return -1;
}
length = get_file_size(fd.get(), CRYPT_FOOTER_OFFSET);