mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2026-06-08 18:14:53 +00:00
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:
@@ -79,10 +79,10 @@ int get_current_time_long(char buf[32])
|
||||
|
||||
time(&t);
|
||||
time_val = localtime((const time_t *)&t);
|
||||
if (!time_val)
|
||||
return -1;
|
||||
|
||||
strftime(buf, 32, "%Y-%m-%d/%H:%M:%S ", time_val);
|
||||
|
||||
return 0;
|
||||
return strftime(buf, 32, "%Y-%m-%d/%H:%M:%S ", time_val);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,6 +286,9 @@ static int reserve_log_folder(enum e_dir_mode mode, char *dir,
|
||||
unsigned int maxdirs;
|
||||
|
||||
crashlog = get_sender_by_name("crashlog");
|
||||
if (!crashlog)
|
||||
return -1;
|
||||
|
||||
outdir = crashlog->outdir;
|
||||
|
||||
switch (mode) {
|
||||
@@ -352,7 +355,9 @@ void generate_crashfile(char *dir, char *event, char *hashkey,
|
||||
const int fmtsize = 128;
|
||||
int filesize;
|
||||
|
||||
get_current_time_long(datetime);
|
||||
ret = get_current_time_long(datetime);
|
||||
if (ret <= 0)
|
||||
return;
|
||||
get_uptime_string(uptime, &hours);
|
||||
|
||||
filesize = fmtsize + strlen(event) +
|
||||
|
||||
Reference in New Issue
Block a user