diff options
| author | 2015-11-03 12:24:17 -0800 | |
|---|---|---|
| committer | 2015-11-03 12:58:12 -0800 | |
| commit | b23f1e077b02a1d62bcf5e34655e8dc979e124fa (patch) | |
| tree | 854c4a7afe2e62e9ead4a10ce17422e3923a1502 /tools/aapt2/ResourceUtils.cpp | |
| parent | 2ae4a877d1623f851040ce69239552c873f1abf0 (diff) | |
AAPT2: Verify positional Java String format arguments in strings
Change-Id: Id415969035a0d5712857c0e11e140155566a960c
Diffstat (limited to 'tools/aapt2/ResourceUtils.cpp')
| -rw-r--r-- | tools/aapt2/ResourceUtils.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp index ae3b4ff1e363..d3c3c1044ae7 100644 --- a/tools/aapt2/ResourceUtils.cpp +++ b/tools/aapt2/ResourceUtils.cpp @@ -328,18 +328,36 @@ std::unique_ptr<BinaryPrimitive> tryParseColor(const StringPiece16& str) { return error ? std::unique_ptr<BinaryPrimitive>() : util::make_unique<BinaryPrimitive>(value); } -std::unique_ptr<BinaryPrimitive> tryParseBool(const StringPiece16& str) { +bool tryParseBool(const StringPiece16& str, bool* outValue) { StringPiece16 trimmedStr(util::trimWhitespace(str)); - uint32_t data = 0; if (trimmedStr == u"true" || trimmedStr == u"TRUE") { - data = 0xffffffffu; - } else if (trimmedStr != u"false" && trimmedStr != u"FALSE") { - return {}; + if (outValue) { + *outValue = true; + } + return true; + } else if (trimmedStr == u"false" || trimmedStr == u"FALSE") { + if (outValue) { + *outValue = false; + } + return true; } - android::Res_value value = { }; - value.dataType = android::Res_value::TYPE_INT_BOOLEAN; - value.data = data; - return util::make_unique<BinaryPrimitive>(value); + return false; +} + +std::unique_ptr<BinaryPrimitive> tryParseBool(const StringPiece16& str) { + bool result = false; + if (tryParseBool(str, &result)) { + android::Res_value value = {}; + value.dataType = android::Res_value::TYPE_INT_BOOLEAN; + + if (result) { + value.data = 0xffffffffu; + } else { + value.data = 0; + } + return util::make_unique<BinaryPrimitive>(value); + } + return {}; } std::unique_ptr<BinaryPrimitive> tryParseInt(const StringPiece16& str) { |