Skip to content

Commit aba91a8

Browse files
yonghuahwenlingz
authored andcommitted
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>
1 parent 995efc1 commit aba91a8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/acrn-manager/acrn_vm_ops.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static inline int _get_vmname_pid(const char *src, char *p_vmname,
7474
int max_len_vmname, int *pid)
7575
{
7676
char *p = NULL;
77+
long val64;
7778

7879
p = strchr(src, '.');
7980
/* 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,
8889
else
8990
p = p + strlen(".monitor.");
9091

91-
*pid = strtol(p, NULL, 10);
92-
if ((errno == ERANGE && (*pid == LONG_MAX || *pid == LONG_MIN))
93-
|| (errno != 0 && *pid == 0))
92+
val64 = strtol(p, NULL, 10);
93+
if ((errno == ERANGE && (val64 == LONG_MAX || val64 == LONG_MIN))
94+
|| (errno != 0 && val64 == 0))
9495
return -1;
9596

97+
*pid = (int)val64;
98+
9699
p = strchr(p, '.');
97100
if (!p || strncmp(".socket", p, strlen(".socket")))
98101
return -1;

0 commit comments

Comments
 (0)