diff options
author | Mike Lockwood <lockwood@android.com> | 2011-07-07 12:22:34 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2011-07-07 12:22:34 -0400 |
commit | 5a34599bae6690eb529d9907737c8a1cfd8efb81 (patch) | |
tree | b712264e92a22d648d256ac9aed89f057c471a42 /android/sqlite3_android.cpp | |
parent | 8f2498715a3164869578e505475495525ee55b28 (diff) |
Allow _DELETE_FILE trigger to delete files on secondary external storage
Change-Id: I5281dda013f909c050fda712d3a0816173df277d
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'android/sqlite3_android.cpp')
-rw-r--r-- | android/sqlite3_android.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/android/sqlite3_android.cpp b/android/sqlite3_android.cpp index 34e08b4..98e3811 100644 --- a/android/sqlite3_android.cpp +++ b/android/sqlite3_android.cpp @@ -212,17 +212,33 @@ static void delete_file(sqlite3_context * context, int argc, sqlite3_value ** ar } char const * path = (char const *)sqlite3_value_text(argv[0]); - char const * external_storage = getenv("EXTERNAL_STORAGE"); - if (path == NULL || external_storage == NULL) { + // Don't allow ".." in paths + if (path == NULL || strstr(path, "/../") != NULL) { sqlite3_result_null(context); return; } - if (strncmp(external_storage, path, strlen(external_storage)) != 0) { - sqlite3_result_null(context); - return; + // We only allow deleting files in the EXTERNAL_STORAGE path, or one of the + // SECONDARY_STORAGE paths + bool good_path = false; + char const * external_storage = getenv("EXTERNAL_STORAGE"); + if (external_storage && strncmp(external_storage, path, strlen(external_storage)) == 0) { + good_path = true; + } else { + // check SECONDARY_STORAGE, which should be a colon separated list of paths + char const * secondary_paths = getenv("SECONDARY_STORAGE"); + while (secondary_paths && secondary_paths[0]) { + const char* colon = strchr(secondary_paths, ':'); + int length = (colon ? colon - secondary_paths : strlen(secondary_paths)); + if (strncmp(secondary_paths, path, length) == 0) { + good_path = true; + } + secondary_paths += length; + while (*secondary_paths == ':') secondary_paths++; + } } - if (strstr(path, "/../") != NULL) { + + if (!good_path) { sqlite3_result_null(context); return; } |