summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-09-25 21:19:04 (GMT)
committerThe Android Automerger <android-build@google.com>2013-09-25 22:03:15 (GMT)
commite1a64ef38f1effbe99cc8149cb2706df0f1f5916 (patch)
tree624388e9f63616366bd4f41cf8d345864e95204a
parent8d8093bf7549e9c4808d3acf8be38d7f7572560f (diff)
downloadandroid_packages_providers_DownloadProvider-e1a64ef38f1effbe99cc8149cb2706df0f1f5916.zip
android_packages_providers_DownloadProvider-e1a64ef38f1effbe99cc8149cb2706df0f1f5916.tar.gz
android_packages_providers_DownloadProvider-e1a64ef38f1effbe99cc8149cb2706df0f1f5916.tar.bz2
Always check against canonical paths.
Bug: 10920351 Change-Id: I8c7e5344d9fd9d15565eaf93b91ce457a98ab98c
-rw-r--r--src/com/android/providers/downloads/Helpers.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index aa763de..013faf2 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -344,16 +344,26 @@ public class Helpers {
* Checks whether the filename looks legitimate
*/
static boolean isFilenameValid(String filename, File downloadsDataDir) {
+ final String[] whitelist;
try {
filename = new File(filename).getCanonicalPath();
+ whitelist = new String[] {
+ downloadsDataDir.getCanonicalPath(),
+ Environment.getDownloadCacheDirectory().getCanonicalPath(),
+ Environment.getExternalStorageDirectory().getCanonicalPath(),
+ };
} catch (IOException e) {
Log.w(TAG, "Failed to resolve canonical path: " + e);
return false;
}
- return filename.startsWith(Environment.getDownloadCacheDirectory().toString())
- || filename.startsWith(downloadsDataDir.toString())
- || filename.startsWith(Environment.getExternalStorageDirectory().toString());
+ for (String test : whitelist) {
+ if (filename.startsWith(test)) {
+ return true;
+ }
+ }
+
+ return false;
}
/**