summaryrefslogtreecommitdiff
path: root/tools/aapt2/configuration/ConfigurationParser.cpp
diff options
context:
space:
mode:
authorShane Farmer <safarmer@google.com>2017-12-06 14:39:10 -0800
committerShane Farmer <safarmer@google.com>2017-12-12 16:25:26 -0800
commit67e8a3074d7ef42734d44f3a8d87635e201bd660 (patch)
treecd5931f49e35ec7943f166d05f8c5410ac0b1ef7 /tools/aapt2/configuration/ConfigurationParser.cpp
parentd87c6b51f55985e343cf96f57b06e4adebf53d25 (diff)
AAPT2: Add validation for SDK version strings.
Ensure that the configured min max and target SDK versions of the android-sdk configuration item are correct. This will prevent AAPT2 crashing when it tries to dereference the Android SDK version to update the manifest. The test for the latest development SDK version has also been made future proof by using the SDK constants. Test: unit tests Test: manually split an APK Change-Id: I1ffa90ba2d96cab0cbfa4bd75ef37a50d986852d
Diffstat (limited to 'tools/aapt2/configuration/ConfigurationParser.cpp')
-rw-r--r--tools/aapt2/configuration/ConfigurationParser.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/tools/aapt2/configuration/ConfigurationParser.cpp b/tools/aapt2/configuration/ConfigurationParser.cpp
index b99240f0a40a..852ff176ed7d 100644
--- a/tools/aapt2/configuration/ConfigurationParser.cpp
+++ b/tools/aapt2/configuration/ConfigurationParser.cpp
@@ -519,14 +519,22 @@ ConfigurationParser::ActionHandler ConfigurationParser::android_sdk_group_handle
} else {
AndroidSdk entry;
for (const auto& attr : child->attributes) {
+ Maybe<int>* target = nullptr;
if (attr.name == "minSdkVersion") {
- entry.min_sdk_version = ResourceUtils::ParseSdkVersion(attr.value);
+ target = &entry.min_sdk_version;
} else if (attr.name == "targetSdkVersion") {
- entry.target_sdk_version = ResourceUtils::ParseSdkVersion(attr.value);
+ target = &entry.target_sdk_version;
} else if (attr.name == "maxSdkVersion") {
- entry.max_sdk_version = ResourceUtils::ParseSdkVersion(attr.value);
+ target = &entry.max_sdk_version;
} else {
diag->Warn(DiagMessage() << "Unknown attribute: " << attr.name << " = " << attr.value);
+ continue;
+ }
+
+ *target = ResourceUtils::ParseSdkVersion(attr.value);
+ if (!*target) {
+ diag->Error(DiagMessage() << "Invalid attribute: " << attr.name << " = " << attr.value);
+ valid = false;
}
}