summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2016-02-16 23:10:32 (GMT)
committerThe Android Automerger <android-build@google.com>2016-03-01 23:26:56 (GMT)
commite74ee404073426ec7d223bee37c9a3de334dffd9 (patch)
treeb6db650366af781f3c698c45601a0a4320016258
parent8ec005728d47e282d72801b4bb43c9a3ea8f717f (diff)
downloadandroid_packages_providers_DownloadProvider-e74ee404073426ec7d223bee37c9a3de334dffd9.zip
android_packages_providers_DownloadProvider-e74ee404073426ec7d223bee37c9a3de334dffd9.tar.gz
android_packages_providers_DownloadProvider-e74ee404073426ec7d223bee37c9a3de334dffd9.tar.bz2
DO NOT MERGE. Use resolved path when inserting and deleting.
This avoids a race condition where someone can change a symlink target after the security checks have passed. Bug: 26211054 Change-Id: I03b06b746fde5d08d6b61a7011bdace0b4e9fa77
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index 620085f..d9acc78 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -715,7 +715,13 @@ public final class DownloadProvider extends ContentProvider {
throw new IllegalArgumentException("Invalid file URI: " + uri);
}
- final File file = new File(path);
+ final File file;
+ try {
+ file = new File(path).getCanonicalFile();
+ } catch (IOException e) {
+ throw new SecurityException(e);
+ }
+
if (Helpers.isFilenameValidInExternalPackage(getContext(), file, getCallingPackage())) {
// No permissions required for paths belonging to calling package
return;
@@ -1191,10 +1197,14 @@ public final class DownloadProvider extends ContentProvider {
final String path = cursor.getString(1);
if (!TextUtils.isEmpty(path)) {
- final File file = new File(path);
- if (Helpers.isFilenameValid(getContext(), file)) {
- Log.v(Constants.TAG, "Deleting " + file + " via provider delete");
- file.delete();
+ try {
+ final File file = new File(path).getCanonicalFile();
+ if (Helpers.isFilenameValid(getContext(), file)) {
+ Log.v(Constants.TAG,
+ "Deleting " + file + " via provider delete");
+ file.delete();
+ }
+ } catch (IOException ignored) {
}
}
}