summaryrefslogtreecommitdiff
path: root/tools/aapt/Resource.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2016-08-15 23:11:37 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-08-15 23:11:37 +0000
commit646f2d9c33677ab30f93011ddf575bb9f9c1a02d (patch)
tree190b9e0604b5ce8212828afb19532e127a24f523 /tools/aapt/Resource.cpp
parent273f01785d216b0ca7e5cacac60ddc507db61493 (diff)
parent193ed74c2d9228368941de948fe03e05ca7fd3e3 (diff)
AAPT: Fix use-after-free error
am: 193ed74c2d Change-Id: I04cd726dae52c5010ad99409f0f77a10267bdeed
Diffstat (limited to 'tools/aapt/Resource.cpp')
-rw-r--r--tools/aapt/Resource.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp
index a7878d196c15..5f91f17b05a3 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;