diff options
author | 2016-08-15 23:22:04 +0000 | |
---|---|---|
committer | 2016-08-15 23:22:04 +0000 | |
commit | 9e8da4a476d1a52d4c287747b5e1b80f61681c15 (patch) | |
tree | 415c89cc359a913198e11d65441b64a92149b472 /tools/aapt/Resource.cpp | |
parent | f0cbd6244c2cd9767be7ac2360e1e3a762ca8420 (diff) | |
parent | 646f2d9c33677ab30f93011ddf575bb9f9c1a02d (diff) |
AAPT: Fix use-after-free error am: 193ed74c2d
am: 646f2d9c33
Change-Id: If9fe7a52e62ae6b2900aa187996b4b785894ab03
Diffstat (limited to 'tools/aapt/Resource.cpp')
-rw-r--r-- | tools/aapt/Resource.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index fa59621ef26d..696120c88ae1 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -1033,7 +1033,6 @@ static ssize_t extractPlatformBuildVersion(AssetManager& assets, Bundle* bundle) return NO_ERROR; } - ResXMLTree tree; Asset* asset = assets.openNonAsset(cookie, "AndroidManifest.xml", Asset::ACCESS_STREAMING); if (asset == NULL) { fprintf(stderr, "ERROR: Platform AndroidManifest.xml not found\n"); @@ -1041,11 +1040,17 @@ static ssize_t extractPlatformBuildVersion(AssetManager& assets, Bundle* bundle) } ssize_t result = NO_ERROR; - if (tree.setTo(asset->getBuffer(true), asset->getLength()) != NO_ERROR) { - fprintf(stderr, "ERROR: Platform AndroidManifest.xml is corrupt\n"); - result = UNKNOWN_ERROR; - } else { - result = extractPlatformBuildVersion(tree, bundle); + + // Create a new scope so that ResXMLTree is destroyed before we delete the memory over + // which it iterates (asset). + { + ResXMLTree tree; + if (tree.setTo(asset->getBuffer(true), asset->getLength()) != NO_ERROR) { + fprintf(stderr, "ERROR: Platform AndroidManifest.xml is corrupt\n"); + result = UNKNOWN_ERROR; + } else { + result = extractPlatformBuildVersion(tree, bundle); + } } delete asset; |