diff options
| author | Lena <lena@omega> | 2026-07-01 00:00:00 +0000 |
|---|---|---|
| committer | Lena <lena@omega> | 2026-07-01 00:00:00 +0000 |
| commit | 2c867cf95341daed1509e3cc48fec9de72cfe2f2 (patch) | |
| tree | 75b7bb992da87f0748904fa4216c908fbd29de8f /app/src/main | |
| parent | d804eb4399850fe828462b3a1832a4c9df1541f8 (diff) | |
| download | rsend-2c867cf95341daed1509e3cc48fec9de72cfe2f2.tar.gz | |
app: anchor the picker start path at the storage root
The containment check was a bare prefix match, so a sibling such as
/storage/emulated/0-evil passed for a root of /storage/emulated/0.
Diffstat (limited to 'app/src/main')
| -rw-r--r-- | app/src/main/java/invalid/lena/rsend/FolderPickerActivity.kt | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/app/src/main/java/invalid/lena/rsend/FolderPickerActivity.kt b/app/src/main/java/invalid/lena/rsend/FolderPickerActivity.kt index 1adccf3..097be3b 100644 --- a/app/src/main/java/invalid/lena/rsend/FolderPickerActivity.kt +++ b/app/src/main/java/invalid/lena/rsend/FolderPickerActivity.kt @@ -37,8 +37,7 @@ class FolderPickerActivity : AppCompatActivity() { // Start where the field already points, if that is a directory under the // root; otherwise at the root itself. val start = intent.getStringExtra("start")?.let { File(it) } - current = if (start != null && start.isDirectory && - start.absolutePath.startsWith(root.absolutePath)) start else root + current = if (start != null && start.isDirectory && underRoot(start)) start else root findViewById<Button>(R.id.use).setOnClickListener { setResult(RESULT_OK, Intent().putExtra("path", current.absolutePath)) @@ -80,6 +79,11 @@ class FolderPickerActivity : AppCompatActivity() { } } + // Anchored at a path separator so /storage/emulated/0-evil does not pass + // for a root of /storage/emulated/0. + private fun underRoot(f: File): Boolean = + f.absolutePath == root.absolutePath || f.absolutePath.startsWith(root.absolutePath + "/") + private fun addRow(label: String, dir: File) { val row = layoutInflater.inflate(R.layout.item_dir, list, false) row.findViewById<TextView>(R.id.dirName).text = label |