Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static scan issues #17

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions crashlog/crashutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need to move opendir here?

Copy link
Contributor Author

@xianju6x xianju6x Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable dir going out of scope leaks the storage it points to at line 171.

if (dir == NULL) {
LOGE("No such directory: %s\n",DROPBOX_DIR);
return file_exist;
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need to check the return value of remove()? What's the consequence?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CID 206964: (#2 of 2): Unchecked return value from library (CHECKED_RETURN)
5. check_return Calling remove(path) without checking return value. This library function may fail and return an error code. [Note: The source code implementation of the function has been overridden by a builtin model.]

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*/
Expand Down
7 changes: 4 additions & 3 deletions crashlog/fsutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to use { } for closedir and return 1.

return 1;
else
return 0;
}
return 0;
}

static inline int get_file_size(char *filename) {
Expand Down
5 changes: 4 additions & 1 deletion crashlog/inotify_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
8 changes: 6 additions & 2 deletions crashlog/trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion crashlog/usercrash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading