From 702833e7061e3727c1151764e6126a851964ebd4 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 | 10 +++++++--- crashlog/fsutils.h | 7 ++++--- crashlog/inotify_handler.c | 5 ++++- crashlog/trigger.c | 8 ++++++-- crashlog/usercrash.c | 4 +++- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/crashlog/crashutils.c b/crashlog/crashutils.c index 5a4c120..b66c752 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) { + LOGE("Failed to remove path %s\n", path); + } } /*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) { + LOGE("Failed to remove path %s\n", path); + } /*create type */ snprintf(tmp,sizeof(tmp),"%s",name); /*Set to upper case*/ diff --git a/crashlog/fsutils.h b/crashlog/fsutils.h index 1d2600f..60795e3 100644 --- a/crashlog/fsutils.h +++ b/crashlog/fsutils.h @@ -88,10 +88,11 @@ static inline int dir_exists(const char *dirpath) { DIR * dir; dir = opendir(dirpath); - if (dir != NULL) + if (dir != NULL) { + closedir(dirpath); return 1; - else - return 0; + } + return 0; } static inline int get_file_size(char *filename) { 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..257bee1 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) { + LOGE("Failed to remove path %s\n", path); + } } /*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) { + LOGE("Failed to remove path %s\n", path); + } /*create type */ snprintf(tmp,sizeof(tmp),"%s",event->name); p = strstr(tmp,"_trigger"); diff --git a/crashlog/usercrash.c b/crashlog/usercrash.c index d5d598a..9c7e2d6 100644 --- a/crashlog/usercrash.c +++ b/crashlog/usercrash.c @@ -116,7 +116,9 @@ 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); + } break; default: LOGE("%s: Unexpected type of event(%d)\n", __FUNCTION__, entry->eventtype);