summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
Diffstat (limited to 'updater')
-rw-r--r--updater/Android.bp9
-rw-r--r--updater/Android.mk3
-rw-r--r--updater/blockimg.cpp8
-rw-r--r--updater/commands.cpp3
-rw-r--r--updater/include/private/commands.h2
-rw-r--r--updater/install.cpp10
-rw-r--r--updater/target_files.cpp13
-rw-r--r--updater/updater.cpp9
-rw-r--r--updater/updater_runtime.cpp40
9 files changed, 61 insertions, 36 deletions
diff --git a/updater/Android.bp b/updater/Android.bp
index f00a192b9..840e50ab9 100644
--- a/updater/Android.bp
+++ b/updater/Android.bp
@@ -12,6 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "bootable_recovery_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["bootable_recovery_license"],
+}
+
cc_defaults {
name: "libupdater_static_libs",
diff --git a/updater/Android.mk b/updater/Android.mk
index 46300d974..ddd4d864a 100644
--- a/updater/Android.mk
+++ b/updater/Android.mk
@@ -72,6 +72,9 @@ endef
include $(CLEAR_VARS)
LOCAL_MODULE := updater
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
+LOCAL_LICENSE_CONDITIONS := notice
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../NOTICE
LOCAL_SRC_FILES := \
updater_main.cpp
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
index 2d41f610b..b29aa8ce3 100644
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -348,7 +348,7 @@ class RangeSinkWriter {
*/
struct NewThreadInfo {
ZipArchiveHandle za;
- ZipEntry entry;
+ ZipEntry64 entry{};
bool brotli_compressed;
std::unique_ptr<RangeSinkWriter> writer;
@@ -1626,7 +1626,7 @@ static bool Sha1DevicePath(const std::string& path, uint8_t digest[SHA_DIGEST_LE
static Value* PerformBlockImageUpdate(const char* name, State* state,
const std::vector<std::unique_ptr<Expr>>& argv,
const CommandMap& command_map, bool dryrun) {
- CommandParameters params = {};
+ CommandParameters params{};
stash_map.clear();
params.canwrite = !dryrun;
@@ -1687,7 +1687,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
}
std::string_view path_data(patch_data_fn->data);
- ZipEntry patch_entry;
+ ZipEntry64 patch_entry;
if (FindEntry(za, path_data, &patch_entry) != 0) {
LOG(ERROR) << name << "(): no file \"" << patch_data_fn->data << "\" in package";
return StringValue("");
@@ -1695,7 +1695,7 @@ static Value* PerformBlockImageUpdate(const char* name, State* state,
params.patch_start = updater->GetMappedPackageAddress() + patch_entry.offset;
std::string_view new_data(new_data_fn->data);
- ZipEntry new_entry;
+ ZipEntry64 new_entry;
if (FindEntry(za, new_data, &new_entry) != 0) {
LOG(ERROR) << name << "(): no file \"" << new_data_fn->data << "\" in package";
return StringValue("");
diff --git a/updater/commands.cpp b/updater/commands.cpp
index aed63369c..1a7c272b5 100644
--- a/updater/commands.cpp
+++ b/updater/commands.cpp
@@ -128,7 +128,6 @@ bool Command::ParseTargetInfoAndSourceInfo(const std::vector<std::string>& token
// No stashes, only source ranges.
SourceInfo result(src_hash, src_ranges, {}, {});
- // Sanity check the block count.
if (result.blocks() != src_blocks) {
*err =
android::base::StringPrintf("mismatching block count: %zu (%s) vs %zu", result.blocks(),
@@ -262,7 +261,7 @@ Command Command::Parse(const std::string& line, size_t index, std::string* err)
return {};
}
} else if (op == Type::ABORT) {
- // No-op, other than sanity checking the input args.
+ // Abort takes no arguments, so there's nothing else to check.
if (pos != tokens.size()) {
*err = android::base::StringPrintf("invalid number of args: %zu (expected 0)",
tokens.size() - pos);
diff --git a/updater/include/private/commands.h b/updater/include/private/commands.h
index 79f915434..7a23bb78b 100644
--- a/updater/include/private/commands.h
+++ b/updater/include/private/commands.h
@@ -307,7 +307,7 @@ class Command {
: type_(type),
index_(index),
cmdline_(std::move(cmdline)),
- patch_(std::move(patch)),
+ patch_(patch),
target_(std::move(target)),
source_(std::move(source)),
stash_(std::move(stash)) {}
diff --git a/updater/install.cpp b/updater/install.cpp
index afa5195d0..295965047 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -35,6 +35,7 @@
#include <unistd.h>
#include <utime.h>
+#include <limits>
#include <memory>
#include <string>
#include <vector>
@@ -115,7 +116,7 @@ Value* PackageExtractFileFn(const char* name, State* state,
std::string dest_path = args[1];
ZipArchiveHandle za = state->updater->GetPackageHandle();
- ZipEntry entry;
+ ZipEntry64 entry;
if (FindEntry(za, zip_path, &entry) != 0) {
LOG(ERROR) << name << ": no " << zip_path << " in package";
return StringValue("");
@@ -165,13 +166,18 @@ Value* PackageExtractFileFn(const char* name, State* state,
const std::string& zip_path = args[0];
ZipArchiveHandle za = state->updater->GetPackageHandle();
- ZipEntry entry;
+ ZipEntry64 entry;
if (FindEntry(za, zip_path, &entry) != 0) {
return ErrorAbort(state, kPackageExtractFileFailure, "%s(): no %s in package", name,
zip_path.c_str());
}
std::string buffer;
+ if (entry.uncompressed_length > std::numeric_limits<size_t>::max()) {
+ return ErrorAbort(state, kPackageExtractFileFailure,
+ "%s(): Entry `%s` Uncompressed size exceeds size of address space.", name,
+ zip_path.c_str());
+ }
buffer.resize(entry.uncompressed_length);
int32_t ret =
diff --git a/updater/target_files.cpp b/updater/target_files.cpp
index 919ec4e04..207146f52 100644
--- a/updater/target_files.cpp
+++ b/updater/target_files.cpp
@@ -115,7 +115,7 @@ bool TargetFile::EntryExists(const std::string_view name) const {
}
CHECK(handle_);
- ZipEntry img_entry;
+ ZipEntry64 img_entry;
return FindEntry(handle_, name, &img_entry) == 0;
}
@@ -126,7 +126,7 @@ bool TargetFile::ReadEntryToString(const std::string_view name, std::string* con
}
CHECK(handle_);
- ZipEntry entry;
+ ZipEntry64 entry;
if (auto find_err = FindEntry(handle_, name, &entry); find_err != 0) {
LOG(ERROR) << "failed to find " << name << " in the package: " << ErrorCodeString(find_err);
return false;
@@ -137,6 +137,13 @@ bool TargetFile::ReadEntryToString(const std::string_view name, std::string* con
return true;
}
+ if (entry.uncompressed_length > std::numeric_limits<size_t>::max()) {
+ LOG(ERROR) << "Failed to extract " << name
+ << " because's uncompressed size exceeds size of address space. "
+ << entry.uncompressed_length;
+ return false;
+ }
+
content->resize(entry.uncompressed_length);
if (auto extract_err = ExtractToMemory(
handle_, &entry, reinterpret_cast<uint8_t*>(&content->at(0)), entry.uncompressed_length);
@@ -157,7 +164,7 @@ bool TargetFile::ExtractEntryToTempFile(const std::string_view name,
}
CHECK(handle_);
- ZipEntry entry;
+ ZipEntry64 entry;
if (auto find_err = FindEntry(handle_, name, &entry); find_err != 0) {
LOG(ERROR) << "failed to find " << name << " in the package: " << ErrorCodeString(find_err);
return false;
diff --git a/updater/updater.cpp b/updater/updater.cpp
index 8f4a6ede5..c52673462 100644
--- a/updater/updater.cpp
+++ b/updater/updater.cpp
@@ -163,14 +163,19 @@ void Updater::ParseAndReportErrorCode(State* state) {
bool Updater::ReadEntryToString(ZipArchiveHandle za, const std::string& entry_name,
std::string* content) {
- ZipEntry entry;
+ ZipEntry64 entry;
int find_err = FindEntry(za, entry_name, &entry);
if (find_err != 0) {
LOG(ERROR) << "failed to find " << entry_name
<< " in the package: " << ErrorCodeString(find_err);
return false;
}
-
+ if (entry.uncompressed_length > std::numeric_limits<size_t>::max()) {
+ LOG(ERROR) << "Failed to extract " << entry_name
+ << " because's uncompressed size exceeds size of address space. "
+ << entry.uncompressed_length;
+ return false;
+ }
content->resize(entry.uncompressed_length);
int extract_err = ExtractToMemory(za, &entry, reinterpret_cast<uint8_t*>(&content->at(0)),
entry.uncompressed_length);
diff --git a/updater/updater_runtime.cpp b/updater/updater_runtime.cpp
index e93830505..bac078cf9 100644
--- a/updater/updater_runtime.cpp
+++ b/updater/updater_runtime.cpp
@@ -44,29 +44,25 @@ std::string UpdaterRuntime::FindBlockDeviceName(const std::string_view name) con
return std::string(name);
}
-static struct {
- const char* name;
- unsigned flag;
-} mount_flags_list[] = {
- { "noatime", MS_NOATIME },
- { "noexec", MS_NOEXEC },
- { "nosuid", MS_NOSUID },
- { "nodev", MS_NODEV },
- { "nodiratime", MS_NODIRATIME },
- { "ro", MS_RDONLY },
- { "rw", 0 },
- { "remount", MS_REMOUNT },
- { "bind", MS_BIND },
- { "rec", MS_REC },
- { "unbindable", MS_UNBINDABLE },
- { "private", MS_PRIVATE },
- { "slave", MS_SLAVE },
- { "shared", MS_SHARED },
- { "defaults", 0 },
- { 0, 0 },
-};
-
static bool setMountFlag(const std::string& flag, unsigned* mount_flags) {
+ static constexpr std::pair<const char*, unsigned> mount_flags_list[] = {
+ { "noatime", MS_NOATIME },
+ { "noexec", MS_NOEXEC },
+ { "nosuid", MS_NOSUID },
+ { "nodev", MS_NODEV },
+ { "nodiratime", MS_NODIRATIME },
+ { "ro", MS_RDONLY },
+ { "rw", 0 },
+ { "remount", MS_REMOUNT },
+ { "bind", MS_BIND },
+ { "rec", MS_REC },
+ { "unbindable", MS_UNBINDABLE },
+ { "private", MS_PRIVATE },
+ { "slave", MS_SLAVE },
+ { "shared", MS_SHARED },
+ { "defaults", 0 },
+ };
+
for (const auto& [name, value] : mount_flags_list) {
if (flag == name) {
*mount_flags |= value;