Added extra validation for invalid paths.
In normal circumstances, StorageVolume can only be obtained through
StorageManager and hence it will contain a valid path internally. But
the path could be invalid in at least 2 occations:
- App maliciously changed it using reflection.
- Mounted volume was ejected.
This change improves OpenExternalDirectoryActivity so it returns a
RESULT_CANCELED upon receiveving an invalid path.
BUG: 27962875
Change-Id: Ide43968babaa37961c7b704bd289f44eac952e94
diff --git a/src/com/android/documentsui/OpenExternalDirectoryActivity.java b/src/com/android/documentsui/OpenExternalDirectoryActivity.java
index 854be0b..b0e5e4e 100644
--- a/src/com/android/documentsui/OpenExternalDirectoryActivity.java
+++ b/src/com/android/documentsui/OpenExternalDirectoryActivity.java
@@ -212,6 +212,12 @@
break;
}
}
+ if (internalRoot == null) {
+ // Should not happen on normal circumstances, unless app crafted an invalid volume
+ // using reflection or the list of mounted volumes changed.
+ Log.e(TAG, "Didn't find right volume for '" + storageVolume.dump() + "' on " + volumes);
+ return false;
+ }
// Checks if the user has granted the permission already.
final Intent intent = getIntentForExistingPermission(activity, isRoot, internalRoot, file);