From b23f1e077b02a1d62bcf5e34655e8dc979e124fa Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Tue, 3 Nov 2015 12:24:17 -0800 Subject: AAPT2: Verify positional Java String format arguments in strings Change-Id: Id415969035a0d5712857c0e11e140155566a960c --- tools/aapt2/ResourceUtils.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'tools/aapt2/ResourceUtils.cpp') 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 tryParseColor(const StringPiece16& str) { return error ? std::unique_ptr() : util::make_unique(value); } -std::unique_ptr 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(value); + return false; +} + +std::unique_ptr 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(value); + } + return {}; } std::unique_ptr tryParseInt(const StringPiece16& str) { -- cgit v1.2.3-59-g8ed1b