Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb39a511 authored by Stephen Hines's avatar Stephen Hines
Browse files

Fix stack-use-after-scope for a `std::string`

`android::util::Utf16ToUtf8()` actually returns a `std::string` due to
the actual conversion to Utf8. `ParseResourceNamedType()` operates on a
`StringPiece` of `converted` (the `std::string` returned from that
call), and stashes it away for later use. Of course, by the time we're
using the `StringPiece` in `parsed_type`, `converted` has already gone
out of scope and is invalid to access.

Bug: http://b/250827883
Test: ./art/test/testrunner/run_build_test_target.py -j80 art-asan

Change-Id: Iea71a5cc84b7dfa96e7dcb549435f8394770a4df
parent 81a53c76
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -43,8 +43,9 @@ namespace ResourceUtils {
static std::optional<ResourceNamedType> ToResourceNamedType(const char16_t* type16,
static std::optional<ResourceNamedType> ToResourceNamedType(const char16_t* type16,
                                                            const char* type, size_t type_len) {
                                                            const char* type, size_t type_len) {
  std::optional<ResourceNamedTypeRef> parsed_type;
  std::optional<ResourceNamedTypeRef> parsed_type;
  std::string converted;
  if (type16) {
  if (type16) {
    auto converted = android::util::Utf16ToUtf8(StringPiece16(type16, type_len));
    converted = android::util::Utf16ToUtf8(StringPiece16(type16, type_len));
    parsed_type = ParseResourceNamedType(converted);
    parsed_type = ParseResourceNamedType(converted);
  } else if (type) {
  } else if (type) {
    parsed_type = ParseResourceNamedType(StringPiece(type, type_len));
    parsed_type = ParseResourceNamedType(StringPiece(type, type_len));