summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2016-01-07 14:15:59 -0700
committerJeff Sharkey <jsharkey@android.com>2016-01-14 14:17:30 -0700
commitbdc831357e7a116bc561d51bf2ddc85ff11c01a9 (patch)
treeae8fe48bbc79c0a044dc0624f6f30d09b11bc0f4 /src
parentf3679d0367cd8a0e72875800decf9f63033645a0 (diff)
downloadandroid_packages_providers_DownloadProvider-bdc831357e7a116bc561d51bf2ddc85ff11c01a9.tar.gz
android_packages_providers_DownloadProvider-bdc831357e7a116bc561d51bf2ddc85ff11c01a9.tar.bz2
android_packages_providers_DownloadProvider-bdc831357e7a116bc561d51bf2ddc85ff11c01a9.zip
Use resolved path for both checking and opening.
This avoids a race condition where someone can change a symlink target after the security checks have passed. Bug: 26211054 Change-Id: I5842aaecc7b7d417a3b1902957b59b8a1f3c1ccb
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java10
-rw-r--r--src/com/android/providers/downloads/Helpers.java1
2 files changed, 8 insertions, 3 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index 4b23024f..2d914c41 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -1230,9 +1230,15 @@ public final class DownloadProvider extends ContentProvider {
throw new FileNotFoundException("No filename found.");
}
- final File file = new File(path);
+ final File file;
+ try {
+ file = new File(path).getCanonicalFile();
+ } catch (IOException e) {
+ throw new FileNotFoundException(e.getMessage());
+ }
+
if (!Helpers.isFilenameValid(getContext(), file)) {
- throw new FileNotFoundException("Invalid file: " + file);
+ throw new FileNotFoundException("Invalid file path: " + file);
}
final int pfdMode = ParcelFileDescriptor.parseMode(mode);
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index 0aa49c0a..1b4c911e 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -341,7 +341,6 @@ public class Helpers {
static boolean isFilenameValid(Context context, File file) {
final File[] whitelist;
try {
- file = file.getCanonicalFile();
whitelist = new File[] {
context.getFilesDir().getCanonicalFile(),
context.getCacheDir().getCanonicalFile(),