Permalink
Browse files

Merge "Refuse to write optimized dex files to a non-private directory."

  • Loading branch information...
2 parents 06f039b + 5c7fa7c commit 990aceacaa21c9d68b6eb4646fd1746f29182be7 Jesse Wilson committed with Android (Google) Code Review Jan 8, 2012
Showing with 16 additions and 0 deletions.
  1. +16 −0 dalvik/src/main/java/dalvik/system/DexFile.java
@@ -20,6 +20,9 @@
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 DexFile(String fileName) throws IOException {
* 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");

0 comments on commit 990acea

Please sign in to comment.