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

coverity: fix coverity issue report in crashlog #29

Open
wants to merge 1 commit into
base: celadon/u/mr0/master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion crashlog/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void add_section(char *config, pconfig_handle conf_handle) {
conf_handle->current->next = newsect;
}
conf_handle->current = newsect;
newsect->name = malloc(strlen(config));
newsect->name = malloc(strlen(config) + 1);
if(!newsect->name) {
if(newsect) {
free(newsect);
Expand Down
9 changes: 5 additions & 4 deletions crashlog/crashutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,14 @@ 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);
DIR *dir;
int file_exist = 0;

if (source == NULL) {
LOGE("source is NULL.\n");
return file_exist;
}
dir = opendir(DROPBOX_DIR);
if (dir == NULL) {
LOGE("No such directory: %s\n",DROPBOX_DIR);
return file_exist;
Expand All @@ -188,9 +189,9 @@ static int find_system_last_kmsg(char *source, int source_length) {
}

void do_last_kmsg_copy(char *dir) {
char destion[PATHMAX];
char source[PATHMAX];
char source[PATHMAX] = {0};
char sourcepath[PATHMAX];
char destion[PATHMAX];

if ( file_exists(LAST_KMSG) ) {
snprintf(destion, sizeof(destion), "%s/%s", dir, LAST_KMSG_FILE);
Expand All @@ -206,7 +207,7 @@ void do_last_kmsg_copy(char *dir) {
snprintf(destion, sizeof(destion), "%s/%s", dir, FTRACE_RAMOOPS_FILE);
do_copy_tail(FTRACE_RAMOOPS, destion, MAXFILESIZE);
}
if (find_system_last_kmsg(&source, sizeof(source))) {
if (find_system_last_kmsg(source, sizeof(source))) {
snprintf(destion, sizeof(destion), "%s/%s", dir, source);
snprintf(sourcepath, sizeof(sourcepath), "%s/%s", DROPBOX_DIR, source);
do_copy_tail(sourcepath, destion, MAXFILESIZE);
Expand Down
6 changes: 6 additions & 0 deletions crashlog/inotify_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ int receive_inotify_events(int inotify_fd) {
}
/* copy the last bytes received */
memcpy(lastevent, buffer, len);
/* Ensure there is enough space in the buffer for missing_bytes */
if (len + missing_bytes > sizeof(lastevent)) {
LOGE("%s: Buffer overflow prevented. The lastevent buffer is too small to hold the additional data.\n",
__FUNCTION__);
return -1;
}
/* now, reads the full last event, including its name field */
res = read(inotify_fd, &lastevent[len], missing_bytes);
if ( res != missing_bytes ) {
Expand Down
2 changes: 1 addition & 1 deletion crashlog/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ int do_monitor() {
return -1;
} else if( get_missing_watched_dir_nb() ) {
/* One or several directories couldn't have been added to inotify watcher */
handle_missing_watched_dir(file_monitor_fd);
handle_missing_watched_dir();
}

/* Set the inotify event callbacks */
Expand Down
3 changes: 3 additions & 0 deletions crashlog/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ static int check_aplogs_tobackup(char *filename) {
LOGE("%s: Cannot transform the property %s(which is %s) into an array... error is %d - %s\n",
__FUNCTION__, PROP_IPANIC_PATTERN, ipanic_chain, nbpatterns, strerror(-nbpatterns));
/* allocated memory is freed in commachain_to_fixedarray */
if (patterns_array_32) {
free(patterns_array_32);
}
return 0;
}
if (nbpatterns == 0) {
Expand Down
2 changes: 1 addition & 1 deletion crashlog/watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void crashlog_wd_handler(int signal,

int enable_watchdog(unsigned int timeout) {
struct sigaction sigact;
struct sigevent sevp;
struct sigevent sevp = {0};
struct itimerspec;

if (timeout == 0)
Expand Down