From 039d4b94d9c304a7a2c05cf23a348a143e341102 Mon Sep 17 00:00:00 2001 From: xianju6x Date: Thu, 21 Mar 2024 09:22:59 +0800 Subject: [PATCH] Fix static scan issues Tracked-On: OAM-110031 Signed-off-by: Zheng, XianjunX --- crashlog/crashutils.c | 16 +++++++++++++--- crashlog/fsutils.h | 1 + crashlog/inotify_handler.c | 5 ++++- crashlog/trigger.c | 14 ++++++++++++-- crashlog/usercrash.c | 7 ++++++- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/crashlog/crashutils.c b/crashlog/crashutils.c index 5a4c120..aebe1e2 100755 --- a/crashlog/crashutils.c +++ b/crashlog/crashutils.c @@ -164,13 +164,13 @@ unsigned long long get_uptime(int refresh, int *error) // Find system last kmsg from dropbox static int find_system_last_kmsg(char source[], int source_length) { struct dirent *entry; - DIR *dir = opendir(DROPBOX_DIR); int file_exist = 0; if (source == NULL) { LOGE("source is NULL.\n"); return file_exist; } + DIR *dir = opendir(DROPBOX_DIR); if (dir == NULL) { LOGE("No such directory: %s\n",DROPBOX_DIR); return file_exist; @@ -808,13 +808,17 @@ int process_info_and_error(char *filename, char *name) { snprintf(path, sizeof(path),"%s/%s", filename,tmp_data_name); snprintf(destion,sizeof(destion),"%s/%s", dir, tmp_data_name); do_copy_tail(path, destion, 0); - remove(path); + if (remove(path) == -1) { + goto failed; + } } /*copy trigger file*/ snprintf(path, sizeof(path),"%s/%s", filename,name); snprintf(destion,sizeof(destion),"%s/%s", dir,name); do_copy_tail(path, destion, 0); - remove(path); + if (remove(path) == -1) { + goto failed; + } /*create type */ snprintf(tmp,sizeof(tmp),"%s",name); /*Set to upper case*/ @@ -832,6 +836,12 @@ int process_info_and_error(char *filename, char *name) { free(key); free(dir); return 0; + +failed: + LOGE("Failed to remove path %s\n", path); + free(key); + free(dir); + return -1; } /** diff --git a/crashlog/fsutils.h b/crashlog/fsutils.h index 1d2600f..328bfdc 100644 --- a/crashlog/fsutils.h +++ b/crashlog/fsutils.h @@ -89,6 +89,7 @@ static inline int dir_exists(const char *dirpath) { dir = opendir(dirpath); if (dir != NULL) + closedir(dirpath); return 1; else return 0; diff --git a/crashlog/inotify_handler.c b/crashlog/inotify_handler.c index 79ca0ab..358eae0 100755 --- a/crashlog/inotify_handler.c +++ b/crashlog/inotify_handler.c @@ -445,7 +445,10 @@ int receive_inotify_events(int inotify_fd) { entry = &wd_array[idx]; } if ( entry && entry->eventpath ) { - mkdir(entry->eventpath, 0777); /* TO DO : restoring previous rights/owner/group ?*/ + if ( mkdir(entry->eventpath, 0777) == -1 ) { /* TO DO : restoring previous rights/owner/group ?*/ + LOGE("Can't mkdir %s.\n", entry->eventpath); + return -1; + } inotify_rm_watch(inotify_fd, event->wd); wd = inotify_add_watch(inotify_fd, entry->eventpath, entry->eventmask); if ( wd < 0 ) { diff --git a/crashlog/trigger.c b/crashlog/trigger.c index 10c1da6..391116f 100644 --- a/crashlog/trigger.c +++ b/crashlog/trigger.c @@ -316,13 +316,17 @@ int process_stat_event(struct watch_entry *entry, struct inotify_event *event) { snprintf(path, sizeof(path), "%s/%s", entry->eventpath, tmp_data_name); snprintf(destination, sizeof(destination), "%s/%s", dir, tmp_data_name); do_copy(path, destination, MAXFILESIZE); - remove(path); + if (remove(path) == -1) { + goto failed; + } } /*copy trigger file*/ snprintf(path, sizeof(path),"%s/%s",entry->eventpath,event->name); snprintf(destination,sizeof(destination),"%s/%s", dir, event->name); do_copy(path, destination, MAXFILESIZE); - remove(path); + if (remove(path) == -1) { + goto failed; + } /*create type */ snprintf(tmp,sizeof(tmp),"%s",event->name); p = strstr(tmp,"_trigger"); @@ -344,4 +348,10 @@ int process_stat_event(struct watch_entry *entry, struct inotify_event *event) { free(key); free(dir); return 0; + +failed: + LOGE("Failed to remove path %s\n", path); + free(key); + free(dir); + return -1; } diff --git a/crashlog/usercrash.c b/crashlog/usercrash.c index d5d598a..074165b 100644 --- a/crashlog/usercrash.c +++ b/crashlog/usercrash.c @@ -116,7 +116,12 @@ static int priv_process_usercrash_event(struct watch_entry *entry, struct inotif do_log_copy(eventname, dir, get_current_time_short(1), APLOG_TYPE); break; case HPROF_TYPE: - remove(path); + if (remove(path) == -1) { + LOGE("Failed to remove path %s\n", path); + free(key); + free(dir); + return -1; + } break; default: LOGE("%s: Unexpected type of event(%d)\n", __FUNCTION__, entry->eventtype);