tools: acrn-crashlog: Fix potential issues under acrnprobe

This patch is to fix potential issues, which are reported by static
analysis tool, for acrnprobe.

Changes:
1. Check the return value of sender_id() and get_sender_by_name(),
   since it could be -1 or NULL.
2. Remove the parameter len from create_event, take parameter path
   as a NULL-terminated string as default.
3. Modify for_each_* functions to avoid overflow.

Signed-off-by: Liu Xinwu <xinwu.liu@intel.com>
Reviewed-by: Zhi Jin <zhi.jin@intel.com>
Acked-by: Chen Gang <gang.c.chen@intel.com>
This commit is contained in:
xiaojin2
2018-06-08 13:15:29 +08:00
committed by lijinxia
parent 0c39b9cddc
commit 3e8e607d5b
7 changed files with 123 additions and 67 deletions

View File

@@ -185,7 +185,7 @@ static void get_log_rotation(struct log_t *log, char *desdir)
if (count > 2) {
for (i = 0; i < count; i++) {
name = strrchr(files[i], '/') + 1;
if (!strstr(name, prefix))
if (!name && !strstr(name, prefix))
continue;
number = atoi(strrchr(name, '.') + 1);
@@ -793,7 +793,7 @@ static void crashlog_send_crash(struct event_t *e)
char *data1;
char *data2;
int id;
int ret;
int ret = 0;
int quota;
struct crash_t *rcrash = (struct crash_t *)e->private;
@@ -931,8 +931,13 @@ static void crashlog_send_reboot(void)
{
char reason[MAXLINESIZE];
char *key;
struct sender_t *crashlog;
if (swupdated(get_sender_by_name("crashlog"))) {
crashlog = get_sender_by_name("crashlog");
if (!crashlog)
return;
if (swupdated(crashlog)) {
key = generate_event_id("INFO", "SWUPDATE");
if (key == NULL) {
LOGE("generate event id failed, error (%s)\n",