summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-04 05:47:15 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-11-04 05:47:15 +0100
commit3e8666172bf1cc7f35d8ca425476e57b86299320 (patch)
treeb64de3607b9e39f2be75b926183fa0c75b54d18f /updater
parentMerge "tests: Set up testdata path for continuous native tests." am: 4011bb161a am: a98b4e4bef am: f35ce240a1 (diff)
parentMerge "updater: Fix an off-by-1 bug in file_getprop()." am: da2b34b5d0 am: 917be35f0f (diff)
downloadandroid_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.gz
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.bz2
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.lz
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.xz
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.tar.zst
android_bootable_recovery-3e8666172bf1cc7f35d8ca425476e57b86299320.zip
Diffstat (limited to 'updater')
-rw-r--r--updater/install.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/updater/install.cpp b/updater/install.cpp
index efc96c454..19ba36534 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -860,9 +860,13 @@ Value* GetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
// file_getprop(file, key)
//
// interprets 'file' as a getprop-style file (key=value pairs, one
-// per line. # comment lines,blank lines, lines without '=' ignored),
+// per line. # comment lines, blank lines, lines without '=' ignored),
// and returns the value for 'key' (or "" if it isn't defined).
Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
+ if (argc != 2) {
+ return ErrorAbort(state, kArgsParsingFailure, "%s() expects 2 args, got %d", name, argc);
+ }
+
std::vector<std::string> args;
if (!ReadArgs(state, 2, argv, &args)) {
return ErrorAbort(state, kArgsParsingFailure, "%s() Failed to parse the argument(s)", name);
@@ -876,11 +880,10 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
filename.c_str(), strerror(errno));
}
-#define MAX_FILE_GETPROP_SIZE 65536
-
+ constexpr off_t MAX_FILE_GETPROP_SIZE = 65536;
if (st.st_size > MAX_FILE_GETPROP_SIZE) {
- return ErrorAbort(state, kFileGetPropFailure, "%s too large for %s (max %d)",
- filename.c_str(), name, MAX_FILE_GETPROP_SIZE);
+ return ErrorAbort(state, kFileGetPropFailure, "%s too large for %s (max %lld)",
+ filename.c_str(), name, static_cast<long long>(MAX_FILE_GETPROP_SIZE));
}
std::string buffer(st.st_size, '\0');
@@ -913,7 +916,7 @@ Value* FileGetPropFn(const char* name, State* state, int argc, Expr* argv[]) {
}
// trim whitespace between key and '='
- std::string str = android::base::Trim(line.substr(0, equal_pos - 1));
+ std::string str = android::base::Trim(line.substr(0, equal_pos));
// not the key we're looking for
if (key != str) continue;