Valid APK paths now include expanded storage.

Apps on expanded storage live at /mnt/expand/<uuid>/app/com.example,
so we need to relax one more directory level.

Bug: 19993667
Change-Id: I347ec7b92435ea69e632ed5d5fdfabe38ce0b56e
This commit is contained in:
Jeff Sharkey 2015-04-06 16:19:39 -07:00
parent 8f43f77de8
commit e23a13299a
4 changed files with 16 additions and 5 deletions

View File

@ -30,6 +30,7 @@ dir_rec_t android_app_dir;
dir_rec_t android_app_private_dir; dir_rec_t android_app_private_dir;
dir_rec_t android_app_lib_dir; dir_rec_t android_app_lib_dir;
dir_rec_t android_media_dir; dir_rec_t android_media_dir;
dir_rec_t android_mnt_expand_dir;
dir_rec_array_t android_system_dirs; dir_rec_array_t android_system_dirs;
int install(const char *pkgname, uid_t uid, gid_t gid, const char *seinfo) int install(const char *pkgname, uid_t uid, gid_t gid, const char *seinfo)

View File

@ -352,6 +352,11 @@ int initialize_globals() {
return -1; return -1;
} }
// Get the android external app directory.
if (get_path_from_string(&android_mnt_expand_dir, "/mnt/expand") < 0) {
return -1;
}
// Take note of the system and vendor directories. // Take note of the system and vendor directories.
android_system_dirs.count = 4; android_system_dirs.count = 4;

View File

@ -101,6 +101,7 @@ extern dir_rec_t android_app_lib_dir;
extern dir_rec_t android_data_dir; extern dir_rec_t android_data_dir;
extern dir_rec_t android_asec_dir; extern dir_rec_t android_asec_dir;
extern dir_rec_t android_media_dir; extern dir_rec_t android_media_dir;
extern dir_rec_t android_mnt_expand_dir;
extern dir_rec_array_t android_system_dirs; extern dir_rec_array_t android_system_dirs;
typedef struct cache_dir_struct { typedef struct cache_dir_struct {

View File

@ -910,14 +910,14 @@ void finish_cache_collection(cache_t* cache)
* The path is allowed to have at most one subdirectory and no indirections * The path is allowed to have at most one subdirectory and no indirections
* to top level directories (i.e. have ".."). * to top level directories (i.e. have "..").
*/ */
static int validate_path(const dir_rec_t* dir, const char* path) { static int validate_path(const dir_rec_t* dir, const char* path, int maxSubdirs) {
size_t dir_len = dir->len; size_t dir_len = dir->len;
const char* subdir = strchr(path + dir_len, '/'); const char* subdir = strchr(path + dir_len, '/');
// Only allow the path to have at most one subdirectory. // Only allow the path to have at most one subdirectory.
if (subdir != NULL) { if (subdir != NULL) {
++subdir; ++subdir;
if (strchr(subdir, '/') != NULL) { if ((--maxSubdirs == 0) && strchr(subdir, '/') != NULL) {
ALOGE("invalid apk path '%s' (subdir?)\n", path); ALOGE("invalid apk path '%s' (subdir?)\n", path);
return -1; return -1;
} }
@ -942,7 +942,7 @@ int validate_system_app_path(const char* path) {
for (i = 0; i < android_system_dirs.count; i++) { for (i = 0; i < android_system_dirs.count; i++) {
const size_t dir_len = android_system_dirs.dirs[i].len; const size_t dir_len = android_system_dirs.dirs[i].len;
if (!strncmp(path, android_system_dirs.dirs[i].path, dir_len)) { if (!strncmp(path, android_system_dirs.dirs[i].path, dir_len)) {
return validate_path(android_system_dirs.dirs + i, path); return validate_path(android_system_dirs.dirs + i, path, 1);
} }
} }
@ -1042,6 +1042,7 @@ int copy_and_append(dir_rec_t* dst, const dir_rec_t* src, const char* suffix) {
int validate_apk_path(const char *path) int validate_apk_path(const char *path)
{ {
const dir_rec_t* dir = NULL; const dir_rec_t* dir = NULL;
int maxSubdirs = 1;
if (!strncmp(path, android_app_dir.path, android_app_dir.len)) { if (!strncmp(path, android_app_dir.path, android_app_dir.len)) {
dir = &android_app_dir; dir = &android_app_dir;
@ -1049,11 +1050,14 @@ int validate_apk_path(const char *path)
dir = &android_app_private_dir; dir = &android_app_private_dir;
} else if (!strncmp(path, android_asec_dir.path, android_asec_dir.len)) { } else if (!strncmp(path, android_asec_dir.path, android_asec_dir.len)) {
dir = &android_asec_dir; dir = &android_asec_dir;
} else if (!strncmp(path, android_mnt_expand_dir.path, android_mnt_expand_dir.len)) {
dir = &android_mnt_expand_dir;
maxSubdirs = 2;
} else { } else {
return -1; return -1;
} }
return validate_path(dir, path); return validate_path(dir, path, maxSubdirs);
} }
int append_and_increment(char** dst, const char* src, size_t* dst_size) { int append_and_increment(char** dst, const char* src, size_t* dst_size) {