From: Jeon Sang-Heon Date: Thu, 30 Jul 2020 20:04:24 +0000 (+0000) Subject: Check delta more strictly X-Git-Tag: submit/tizen/20200807.173049~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b8f019d0b8fba02b832dcfd014e669b95e0cf3bc;p=platform%2Fcore%2Fsystem%2Fupdate-control.git Check delta more strictly - Current delta verify only check target's build string - Check that new version build string matches with delta additionally - Devide fota delta verify into fota-delta-verifier file - Minor changes for log Change-Id: Idfdf4c5b268f060dee0fea9e873242e3cf1d6587 Signed-off-by: Jeon Sang-Heon --- diff --git a/update-manager/common/common-boot-status-checker.c b/update-manager/common/common-boot-status-checker.c index 13f8e36..aa60423 100644 --- a/update-manager/common/common-boot-status-checker.c +++ b/update-manager/common/common-boot-status-checker.c @@ -23,10 +23,10 @@ void common_boot_status_checker_callback(keynode_t *node, void *user_data) else _W("vconf_ignore_key_changed for %s failed : %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret); - _I("Success to get bootstatus success, try process fota event"); + _FLOGI("Success to get bootstatus success, try process fota event"); ret = fota_client_controller_process_event(); if (ret < 0) - _E("Failed to process fota client event : %d", ret); + _FLOGE("Failed to process fota client event : %d", ret); _RLOGI("Success to get bootstatus success, try process recovery event"); ret = recovery_client_controller_process_event(); diff --git a/update-manager/fota-controller.c b/update-manager/fota-controller.c index 4cea23a..ef81437 100644 --- a/update-manager/fota-controller.c +++ b/update-manager/fota-controller.c @@ -1,60 +1,10 @@ #include "fota/fota-manager.h" #include "update-manager.h" -int fota_controller_verify_delta(const char *delta_path) -{ - int ret = 0, status = 0; - char buf[MAX_BUFFER_SIZE] = {0, }; - char *build_id = NULL; - - if (g_file_test(delta_path, G_FILE_TEST_EXISTS)) { - _I("Found delta in %s, start process to verify", delta_path); - - ret = util_file_untar(delta_path, BUILD_ID_DIR, BUILD_ID_FILE); - if (ret < 0) { - _E("Failed to fetch %s from delta : %d", BUILD_ID_FILE, ret); - status = -1; - goto verify_destroy; - } - - build_id = fota_info_get_build_string(); - if (build_id == NULL) { - _E("Failed to get current build id"); - status = -1; - goto verify_destroy; - } - - ret = util_file_read_line(BUILD_ID_PATH, buf); - if (ret < 0) { - _E("Failed to read delta build id : %d", ret); - status = -1; - goto verify_destroy; - } - - if (g_strrstr(buf, build_id) != NULL) { - _I("Delta build id matched : %s", build_id); - } else { - _I("Delta build id unmatched, current : %s, delta : %s", - build_id, buf); - status = 1; - } - } else { - _I("Not found delta in %s", delta_path); - status = 2; - } - -verify_destroy: - ret = remove(BUILD_ID_PATH); - if (ret < 0) - _W("Failed to remove %s : %m", BUILD_ID_PATH); - - return status; -} - int fota_controller_setup_delta() { int ret = 0, status = 0; - char *appid = NULL; + char *appid = NULL, *build_string = NULL; gchar *shared_path = NULL; ret = util_file_mkdir(FOTA_DIR); @@ -70,12 +20,19 @@ int fota_controller_setup_delta() goto delta_destroy; } + build_string = fota_info_get_build_string(); + if (build_string == NULL) { + _E("Failed to get build string"); + status = -1; + goto delta_destroy; + } + ret = remove(FOTA_DELTA_PATH); if (ret < 0 && errno != ENOENT) _W("Failed to remove exist link : %m"); shared_path = g_strjoin("/", SHARED_DIR, appid, SHARED_DATA_DIR, FOTA_DELTA_FILE, NULL); - ret = fota_controller_verify_delta(shared_path); + ret = fota_delta_verify(shared_path, build_string, NULL); if (ret != 0) { _E("Failed to verify delta : %d", ret); status = -1; diff --git a/update-manager/fota/fota-delta-verifier.c b/update-manager/fota/fota-delta-verifier.c new file mode 100644 index 0000000..a02af04 --- /dev/null +++ b/update-manager/fota/fota-delta-verifier.c @@ -0,0 +1,74 @@ +#include "fota-manager.h" +#include "../update-manager.h" + +int fota_delta_verify(const char *path, const char *old_build_string, const char *new_build_string) +{ + int ret = 0, status = 0; + char buf[MAX_BUFFER_SIZE] = {0, }; + FILE *fp = NULL; + + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { + _FLOGI("Not found delta in %s", path); + status = 1; + goto verify_destroy; + } + + if (old_build_string == NULL) { + _FLOGE("Failed to try verify, old build string must be passed"); + status = -1; + goto verify_destroy; + } + + _FLOGI("Found delta in %s, start process to verify", path); + ret = util_file_untar(path, BUILD_ID_DIR, BUILD_ID_FILE); + if (ret < 0) { + _FLOGE("Failed to fetch %s from delta : %d", BUILD_ID_FILE, ret); + status = -1; + goto verify_destroy; + } + + fp = fopen(BUILD_ID_PATH, "r"); + if (fp == NULL) { + _FLOGE("Failed to open : %s", BUILD_ID_PATH); + status = -1; + goto verify_destroy; + } + + if (fgets(buf, MAX_BUFFER_SIZE, fp) == NULL) { + _FLOGE("Failed to read : %s", BUILD_ID_PATH); + status = -1; + goto verify_destroy; + } + + if (g_strrstr(buf, old_build_string) == NULL) { + _FLOGI("Unmatched occur, old_build_string : %s, delta : %s", old_build_string, buf); + status = 2; + goto verify_destroy; + } + + if (new_build_string != NULL) { + if (fgets(buf, MAX_BUFFER_SIZE, fp) == NULL) { + _FLOGE("Failed to read : %s", BUILD_ID_PATH); + status = -1; + goto verify_destroy; + } + + if (g_strrstr(buf, new_build_string) == NULL) { + _FLOGI("Unmatched occur, new_build_string : %s, delta : %s", new_build_string, buf); + status = 3; + goto verify_destroy; + } + } + + _FLOGI("Success to verify %s, old : %s, new : %s", path, old_build_string, new_build_string); + +verify_destroy: + ret = remove(BUILD_ID_PATH); + if (ret < 0) + _FLOGW("Failed to remove %s : %m", BUILD_ID_PATH); + + if (!fp) + fclose(fp); + + return status; +} \ No newline at end of file diff --git a/update-manager/fota/fota-manager.h b/update-manager/fota/fota-manager.h index a279fbd..2940c3e 100644 --- a/update-manager/fota/fota-manager.h +++ b/update-manager/fota/fota-manager.h @@ -24,6 +24,8 @@ #define FOTA_EVENT_SIZE 3 +#define FOTA_LOCAL_FOLDER_TOKEN "@" + /* Enum */ typedef enum { FOTA_EVENT_PLUG = 0, @@ -39,6 +41,8 @@ int fota_client_info_checker_init(void); int fota_client_info_checker_fini(void); char *fota_client_info_get_appid(void); +int fota_delta_verify(const char *, const char *, const char *); + int fota_info_checker_init(void); int fota_info_checker_fini(void); char *fota_info_get_build_string(void); diff --git a/update-manager/fota/fota-status-checker.c b/update-manager/fota/fota-status-checker.c index c4e8409..a23af6d 100644 --- a/update-manager/fota/fota-status-checker.c +++ b/update-manager/fota/fota-status-checker.c @@ -18,7 +18,7 @@ int fota_status_checker_init() return 0; } - ret = util_file_read_line(STATUS_RESULT_PATH, buf); + ret = util_file_read_single_line(STATUS_RESULT_PATH, buf); if (ret < 0) { _FLOGE("Failed to read fota result : %d", ret); return -1; diff --git a/update-manager/fota/fota-storage-checker.c b/update-manager/fota/fota-storage-checker.c index ed04d7d..529337e 100644 --- a/update-manager/fota/fota-storage-checker.c +++ b/update-manager/fota/fota-storage-checker.c @@ -3,10 +3,59 @@ static int fota_storage_id = -1; +int fota_storage_verify_delta(const char* mount_path, const char *folder_name, gchar **delta_path) +{ + int ret = 0, status = 0; + char *old_build_string = NULL; + gchar *new_build_string = NULL, *path = NULL; + + old_build_string = fota_info_get_build_string(); + if (old_build_string == NULL) { + _FLOGE("Failed to get build string"); + status = -1; + goto verify_destroy; + } + + if (g_str_has_prefix(folder_name, old_build_string) != TRUE) { + _FLOGI("Folder %s is not start with %s, pass", folder_name, old_build_string); + goto verify_destroy; + } + + new_build_string = strstr(folder_name, FOTA_LOCAL_FOLDER_TOKEN); + if (new_build_string == NULL) { + _FLOGI("Folder %s doesn't have token : %s", folder_name, FOTA_LOCAL_FOLDER_TOKEN); + goto verify_destroy; + } + new_build_string = new_build_string + 1; + + path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILE, NULL); + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { + _FLOGI("Folder %s doesn't have delta.tar", folder_name); + goto verify_destroy; + } + + ret = fota_delta_verify(path, old_build_string, new_build_string); + if (ret < 0) { + status = -1; + goto verify_destroy; + } + else if (ret > 0) { + goto verify_destroy; + } + + *delta_path = path; + +verify_destroy: + if (status != 0) { + g_free(path); + } + + return status; +} + int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path) { - int status = 0; - char *build_id = NULL; + int ret = 0, status = 0; const gchar *folder_name = NULL; GFile *mount = NULL; GFileEnumerator *enumerator = NULL; @@ -22,33 +71,22 @@ int fota_storage_search_delta_path(const char *mount_path, gchar **delta_path) goto search_destroy; } - build_id = fota_info_get_build_string(); - if (build_id == NULL) { - _FLOGE("Failed to get build id"); - status = -1; - goto search_destroy; - } - while ((info = g_file_enumerator_next_file(enumerator, NULL, NULL)) != NULL) { - if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY) + if (g_file_info_get_file_type(info) != G_FILE_TYPE_DIRECTORY) { + g_object_unref(info); continue; + } folder_name = g_file_info_get_name(info); - if (g_str_has_prefix(folder_name, build_id) == TRUE) { - *delta_path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILE, NULL); - break; + ret = fota_storage_verify_delta(mount_path, folder_name, delta_path); + if (ret < 0) { + _FLOGE("Failed to verify delta : %d, folder : %s", ret, folder_name); + status = -1; } g_object_unref(info); } - if (*delta_path != NULL) { - _FLOGI("Success to find delta path : %s", *delta_path); - } else { - _FLOGI("Failed to find delta path with prefix %s", build_id); - status = 1; - } - search_destroy: if (enumerator) g_object_unref(enumerator); @@ -68,14 +106,13 @@ void fota_storage_checker_plug(int storage_id, const char *mount_path) _FLOGI("Storage mounted with %s, start process to check local delta", mount_path); ret = fota_storage_search_delta_path(mount_path, &delta_path); - if (ret != 0) { + if (ret < 0) { _FLOGE("Failed to find delta path : %d", ret); goto plug_destroy; } - ret = fota_controller_verify_delta(delta_path); - if (ret != 0) { - _FLOGE("Failed to verify delta : %d", ret); + if (delta_path == NULL) { + _FLOGI("Not found matched delta in %s", mount_path); goto plug_destroy; } diff --git a/update-manager/recovery/recovery-storage-checker.c b/update-manager/recovery/recovery-storage-checker.c index 8aef617..95cf957 100644 --- a/update-manager/recovery/recovery-storage-checker.c +++ b/update-manager/recovery/recovery-storage-checker.c @@ -23,7 +23,7 @@ void recovery_storage_checker_plug(int storage_id, const char *mount_path) image_path = g_strjoin("/", mount_path, RECOVERY_IMAGE_FILE, NULL); ret = recovery_storage_search_image(image_path); - if (ret != 0) { + if (ret < 0) { _RLOGE("Failed to find delta path : %d", ret); goto plug_destroy; } diff --git a/update-manager/update-manager.h b/update-manager/update-manager.h index 88e2110..3ad5cc7 100644 --- a/update-manager/update-manager.h +++ b/update-manager/update-manager.h @@ -78,12 +78,11 @@ int common_client_info_checker_filter(const char*, const char*, pkgmgrinfo_app_l int dbus_manager_init(void); int dbus_manager_fini(void); -int fota_controller_verify_delta(const char *); int fota_controller_install(void); int fota_controller_result(void); int util_file_mkdir(const char *); -int util_file_read_line(const char *, char []); +int util_file_read_single_line(const char *, char []); int util_file_write_line(const char *, const char *); int util_file_untar(const char *, const char *, const char *); diff --git a/update-manager/util.c b/update-manager/util.c index 54d6355..7667b10 100644 --- a/update-manager/util.c +++ b/update-manager/util.c @@ -17,7 +17,7 @@ int util_file_mkdir(const char *path) return 0; } -int util_file_read_line(const char *path, char buf[]) +int util_file_read_single_line(const char *path, char buf[]) { int status = 0; FILE *fp = NULL;