summaryrefslogtreecommitdiffstats
path: root/dalvik
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2012-01-08 15:16:31 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-01-08 15:16:31 -0800
commit990aceacaa21c9d68b6eb4646fd1746f29182be7 (patch)
tree560db3c4d6e87946f2e1001867dc3eb8a731c1bc /dalvik
parent06f039b4c39bee1b0618f40d4d4af0d0f2bef2fa (diff)
parent5c7fa7c36acddda7b7cc392ec360116b03e09880 (diff)
downloadlibcore-990aceacaa21c9d68b6eb4646fd1746f29182be7.zip
libcore-990aceacaa21c9d68b6eb4646fd1746f29182be7.tar.gz
libcore-990aceacaa21c9d68b6eb4646fd1746f29182be7.tar.bz2
Merge "Refuse to write optimized dex files to a non-private directory."
Diffstat (limited to 'dalvik')
-rw-r--r--dalvik/src/main/java/dalvik/system/DexFile.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/dalvik/src/main/java/dalvik/system/DexFile.java b/dalvik/src/main/java/dalvik/system/DexFile.java
index dc3e063..8db3985 100644
--- a/dalvik/src/main/java/dalvik/system/DexFile.java
+++ b/dalvik/src/main/java/dalvik/system/DexFile.java
@@ -20,6 +20,9 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
+import libcore.io.ErrnoException;
+import libcore.io.Libcore;
+import libcore.io.StructStat;
/**
* Manipulates DEX files. The class is similar in principle to
@@ -90,6 +93,19 @@ public final class DexFile {
* Enable optional features.
*/
private DexFile(String sourceName, String outputName, int flags) throws IOException {
+ if (outputName != null) {
+ try {
+ String parent = new File(outputName).getParent();
+ if (Libcore.os.getuid() != Libcore.os.stat(parent).st_uid) {
+ throw new IllegalArgumentException("Optimized data directory " + parent
+ + " is not owned by the current user. Shared storage cannot protect"
+ + " your application from code injection attacks.");
+ }
+ } catch (ErrnoException ignored) {
+ // assume we'll fail with a more contextual error later
+ }
+ }
+
mCookie = openDexFile(sourceName, outputName, flags);
mFileName = sourceName;
guard.open("close");