uncrypt: package on non-data partition should follow the right path
Fix the accidental change of behavior in [1]. OTA packages not on /data partition should still go through the path that has validity checks and wipe_misc() steps. [1]: commiteaf33654c1
. Change-Id: I3e86e19f06603bfe6ecc691c9aa66a8a8a79c5fb (cherry picked from commitfb4ccef1df
)
This commit is contained in:
parent
93cec9a0c4
commit
8853cb2f29
1 changed files with 41 additions and 20 deletions
|
@ -159,12 +159,13 @@ const char* find_block_device(const char* path, int* encryptable, int* encrypted
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* parse_recovery_command_file()
|
// Parse the command file RECOVERY_COMMAND_FILE to find the update package
|
||||||
|
// name. If it's on the /data partition, replace the package name with the
|
||||||
|
// block map file name and store it temporarily in RECOVERY_COMMAND_FILE_TMP.
|
||||||
|
// It will be renamed to RECOVERY_COMMAND_FILE if uncrypt finishes
|
||||||
|
// successfully.
|
||||||
|
static char* find_update_package()
|
||||||
{
|
{
|
||||||
char* fn = NULL;
|
|
||||||
int count = 0;
|
|
||||||
char temp[1024];
|
|
||||||
|
|
||||||
FILE* f = fopen(RECOVERY_COMMAND_FILE, "r");
|
FILE* f = fopen(RECOVERY_COMMAND_FILE, "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -175,17 +176,27 @@ char* parse_recovery_command_file()
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
FILE* fo = fdopen(fd, "w");
|
FILE* fo = fdopen(fd, "w");
|
||||||
|
char* fn = NULL;
|
||||||
while (fgets(temp, sizeof(temp), f)) {
|
char* line = NULL;
|
||||||
printf("read: %s", temp);
|
size_t len = 0;
|
||||||
if (strncmp(temp, "--update_package=/data/", strlen("--update_package=/data/")) == 0) {
|
while (getline(&line, &len, f) != -1) {
|
||||||
fn = strdup(temp + strlen("--update_package="));
|
if (strncmp(line, "--update_package=", strlen("--update_package=")) == 0) {
|
||||||
strcpy(temp, "--update_package=@" CACHE_BLOCK_MAP "\n");
|
fn = strdup(line + strlen("--update_package="));
|
||||||
|
// Replace the package name with block map file if it's on /data partition.
|
||||||
|
if (strncmp(fn, "/data/", strlen("/data/")) == 0) {
|
||||||
|
fputs("--update_package=@" CACHE_BLOCK_MAP "\n", fo);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fputs(temp, fo);
|
fputs(line, fo);
|
||||||
}
|
}
|
||||||
|
free(line);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
fsync(fd);
|
if (fsync(fd) == -1) {
|
||||||
|
ALOGE("failed to fsync \"%s\": %s\n", RECOVERY_COMMAND_FILE_TMP, strerror(errno));
|
||||||
|
fclose(fo);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
fclose(fo);
|
fclose(fo);
|
||||||
|
|
||||||
if (fn) {
|
if (fn) {
|
||||||
|
@ -244,7 +255,6 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de
|
||||||
ALOGE("failed to open fd for reading: %s\n", strerror(errno));
|
ALOGE("failed to open fd for reading: %s\n", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fsync(fd);
|
|
||||||
|
|
||||||
int wfd = -1;
|
int wfd = -1;
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
|
@ -319,11 +329,17 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de
|
||||||
fprintf(mapf, "%d %d\n", ranges[i*2], ranges[i*2+1]);
|
fprintf(mapf, "%d %d\n", ranges[i*2], ranges[i*2+1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fsync(mapfd);
|
if (fsync(mapfd) == -1) {
|
||||||
|
ALOGE("failed to fsync \"%s\": %s\n", map_file, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
fclose(mapf);
|
fclose(mapf);
|
||||||
close(fd);
|
close(fd);
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
fsync(wfd);
|
if (fsync(wfd) == -1) {
|
||||||
|
ALOGE("failed to fsync \"%s\": %s\n", blk_dev, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
close(wfd);
|
close(wfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +368,11 @@ void wipe_misc() {
|
||||||
written += w;
|
written += w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fsync(fd);
|
if (fsync(fd) == -1) {
|
||||||
|
ALOGE("failed to fsync \"%s\": %s\n", v->blk_device, strerror(errno));
|
||||||
|
close(fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,7 +403,7 @@ int main(int argc, char** argv)
|
||||||
map_file = argv[2];
|
map_file = argv[2];
|
||||||
do_reboot = 0;
|
do_reboot = 0;
|
||||||
} else {
|
} else {
|
||||||
input_path = parse_recovery_command_file();
|
input_path = find_update_package();
|
||||||
if (input_path == NULL) {
|
if (input_path == NULL) {
|
||||||
// if we're rebooting to recovery without a package (say,
|
// if we're rebooting to recovery without a package (say,
|
||||||
// to wipe data), then we don't need to do anything before
|
// to wipe data), then we don't need to do anything before
|
||||||
|
@ -432,15 +452,16 @@ int main(int argc, char** argv)
|
||||||
if (strncmp(path, "/data/", 6) != 0) {
|
if (strncmp(path, "/data/", 6) != 0) {
|
||||||
// path does not start with "/data/"; leave it alone.
|
// path does not start with "/data/"; leave it alone.
|
||||||
unlink(RECOVERY_COMMAND_FILE_TMP);
|
unlink(RECOVERY_COMMAND_FILE_TMP);
|
||||||
|
wipe_misc();
|
||||||
} else {
|
} else {
|
||||||
ALOGI("writing block map %s", map_file);
|
ALOGI("writing block map %s", map_file);
|
||||||
if (produce_block_map(path, map_file, blk_dev, encrypted) != 0) {
|
if (produce_block_map(path, map_file, blk_dev, encrypted) != 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
wipe_misc();
|
||||||
|
rename(RECOVERY_COMMAND_FILE_TMP, RECOVERY_COMMAND_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
wipe_misc();
|
|
||||||
rename(RECOVERY_COMMAND_FILE_TMP, RECOVERY_COMMAND_FILE);
|
|
||||||
if (do_reboot) reboot_to_recovery();
|
if (do_reboot) reboot_to_recovery();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue