tools: acrn-crashlog: fix potential issues

Changes include:
1. check the parameter of snprintf
2. remove atoi
3. remove sscanf
4. fix one memleak

Tracked-On: #1024
Signed-off-by: Liu, Xinwu <xinwu.liu@intel.com>
Reviewed-by: Huang, Yonghua <yonghua.huang@intel.com>
Acked-by: Chen, Gang <gang.c.chen@intel.com>
This commit is contained in:
Liu, Xinwu
2018-10-30 17:26:44 +08:00
committed by lijinxia
parent 111f9726d0
commit 3ffa9686ca
13 changed files with 236 additions and 118 deletions

View File

@@ -152,7 +152,9 @@ static int get_prop_int(xmlNodePtr cur, const char *key, const int max)
return -1;
}
value = atoi((char *)prop);
if (cfg_atoi((const char *)prop, xmlStrlen(prop), &value) == -1)
return -1;
xmlFree(prop);
if (value > max) {
@@ -379,6 +381,25 @@ int crash_depth(struct crash_t *tcrash)
return level;
}
int cfg_atoi(const char *a, size_t alen, int *i)
{
char *eptr;
int res;
if (!a || !alen || !i)
return -1;
res = (int)strtol(a, &eptr, 0);
if (a + alen != eptr) {
LOGE("Failed to convert (%s) to type int, check config file\n",
a);
return -1;
}
*i = res;
return 0;
}
static int is_enable(xmlNodePtr cur)
{
xmlChar *prop;
@@ -524,8 +545,10 @@ static int parse_crashes(xmlNodePtr crashes)
return -1;
res = get_prop_int(cur, "inherit", CRASH_MAX);
if (res < 0)
if (res < 0) {
free(crash);
return -1;
}
id = res - 1;
if (id >= 0) {