mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-19 20:22:46 +00:00
vm-manager: fix improper return value check for "strtol()"
The return value of 'strtol()' is not checked properly in _get_vmname_pid() @acrn_vm_ops.c and parse_opt()@acnrd.c, the return type of 'strtol' is 'long int', but it is assigned to a variable with type of 'int' and compared to "LONG_MAX" and "LONG_MIN", which is always false. This patch is to fix above error case. Tracked-On: #4088 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Reviewed-by: Yan, Like <like.yan@intel.com> Acked-by: Yan, Like <like.yan@intel.com>
This commit is contained in:
parent
995efc1b6f
commit
aba91a81e4
@ -74,6 +74,7 @@ static inline int _get_vmname_pid(const char *src, char *p_vmname,
|
||||
int max_len_vmname, int *pid)
|
||||
{
|
||||
char *p = NULL;
|
||||
long val64;
|
||||
|
||||
p = strchr(src, '.');
|
||||
/* p - src: length of the substring "vmname" in the sting "src" */
|
||||
@ -88,11 +89,13 @@ static inline int _get_vmname_pid(const char *src, char *p_vmname,
|
||||
else
|
||||
p = p + strlen(".monitor.");
|
||||
|
||||
*pid = strtol(p, NULL, 10);
|
||||
if ((errno == ERANGE && (*pid == LONG_MAX || *pid == LONG_MIN))
|
||||
|| (errno != 0 && *pid == 0))
|
||||
val64 = strtol(p, NULL, 10);
|
||||
if ((errno == ERANGE && (val64 == LONG_MAX || val64 == LONG_MIN))
|
||||
|| (errno != 0 && val64 == 0))
|
||||
return -1;
|
||||
|
||||
*pid = (int)val64;
|
||||
|
||||
p = strchr(p, '.');
|
||||
if (!p || strncmp(".socket", p, strlen(".socket")))
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user