From 9ba5cb4796a66b387af1f9350134f742f490aa7f Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Mon, 24 Sep 2018 15:20:15 -0700 Subject: Do not use StringPiece in ExtractJavaIdentifier Bug: http://b/91353691 After assigning the result of TransformToFieldName to 'result', the underlying storage is destroyed after the 'if' statement of the function call. 'result' ends up with garbage if the identifier has a '-'. ManifestClassGeneratorTest.NormalizePermissionNames is broken for this reason in 32-bit Windows when using libc++ and 32-bit Linux. ASAN also reports this failure for both 32-bit and 64-bit linux. Test: Run test on the cases mentioned above and ensure all of them pass. Change-Id: I69163c423c1171b7ac7838f2abe06bdf8058df4c --- tools/aapt2/java/ManifestClassGenerator.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tools/aapt2/java') diff --git a/tools/aapt2/java/ManifestClassGenerator.cpp b/tools/aapt2/java/ManifestClassGenerator.cpp index be67c9c8c03c..10e504ec0752 100644 --- a/tools/aapt2/java/ManifestClassGenerator.cpp +++ b/tools/aapt2/java/ManifestClassGenerator.cpp @@ -26,21 +26,20 @@ #include "util/Maybe.h" #include "xml/XmlDom.h" -using ::android::StringPiece; using ::aapt::text::IsJavaIdentifier; namespace aapt { -static Maybe ExtractJavaIdentifier(IDiagnostics* diag, const Source& source, +static Maybe ExtractJavaIdentifier(IDiagnostics* diag, const Source& source, const std::string& value) { - StringPiece result = value; + std::string result = value; size_t pos = value.rfind('.'); if (pos != std::string::npos) { result = result.substr(pos + 1); } // Normalize only the java identifier, leave the original value unchanged. - if (result.contains("-")) { + if (result.find("-") != std::string::npos) { result = JavaClassGenerator::TransformToFieldName(result); } @@ -64,7 +63,7 @@ static bool WriteSymbol(const Source& source, IDiagnostics* diag, xml::Element* return false; } - Maybe result = + Maybe result = ExtractJavaIdentifier(diag, source.WithLine(el->line_number), attr->value); if (!result) { return false; -- cgit v1.2.3-59-g8ed1b