Skip to content

Commit c1fc7f5

Browse files
yonghuahwenlingz
authored andcommitted
hv: remove the usage of 'atoi()'
this function is not from libc but has the same name, atoi() in libc is unbounded and not safe. replace this function with 'strtol_deci()' in this case. Tracked-On: #2187 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 536ce5f commit c1fc7f5

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

hypervisor/debug/shell.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,12 @@ static int32_t shell_vcpu_dumpreg(int32_t argc, char **argv)
707707
goto out;
708708
}
709709

710-
status = atoi(argv[1]);
710+
status = strtol_deci(argv[1]);
711711
if (status < 0) {
712712
goto out;
713713
}
714714
vm_id = (uint16_t)status;
715-
vcpu_id = (uint16_t)atoi(argv[2]);
715+
vcpu_id = (uint16_t)strtol_deci(argv[2]);
716716

717717
vm = get_vm_from_vmid(vm_id);
718718
if (vm == NULL) {
@@ -758,7 +758,7 @@ static int32_t shell_dumpmem(int32_t argc, char **argv)
758758
}
759759

760760
addr = strtoul_hex(argv[1]);
761-
length = (uint32_t)atoi(argv[2]);
761+
length = (uint32_t)strtol_deci(argv[2]);
762762
if (length > MAX_MEMDUMP_LEN) {
763763
shell_puts("over max length, round back\r\n");
764764
length = MAX_MEMDUMP_LEN;
@@ -800,7 +800,7 @@ static int32_t shell_to_sos_console(__unused int32_t argc, __unused char **argv)
800800
struct vm_description *vm_desc;
801801

802802
if (argc == 2U) {
803-
guest_no = atoi(argv[1]);
803+
guest_no = strtol_deci(argv[1]);
804804
}
805805

806806
vuart_vmid = guest_no;
@@ -1084,7 +1084,7 @@ static int32_t shell_show_vioapic_info(int32_t argc, char **argv)
10841084
if (argc != 2) {
10851085
return -EINVAL;
10861086
}
1087-
ret = atoi(argv[1]);
1087+
ret = strtol_deci(argv[1]);
10881088
if (ret >= 0) {
10891089
vmid = (uint16_t) ret;
10901090
get_vioapic_info(shell_log_buf, SHELL_LOG_BUF_SIZE, vmid);
@@ -1188,13 +1188,13 @@ static int32_t shell_loglevel(int32_t argc, char **argv)
11881188

11891189
switch (argc) {
11901190
case 4:
1191-
npk_loglevel = (uint16_t)atoi(argv[3]);
1191+
npk_loglevel = (uint16_t)strtol_deci(argv[3]);
11921192
/* falls through */
11931193
case 3:
1194-
mem_loglevel = (uint16_t)atoi(argv[2]);
1194+
mem_loglevel = (uint16_t)strtol_deci(argv[2]);
11951195
/* falls through */
11961196
case 2:
1197-
console_loglevel = (uint16_t)atoi(argv[1]);
1197+
console_loglevel = (uint16_t)strtol_deci(argv[1]);
11981198
break;
11991199
case 1:
12001200
snprintf(str, MAX_STR_SIZE, "console_loglevel: %u, "

hypervisor/debug/string.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,3 @@ int64_t strtol_deci(const char *nptr)
8484
}
8585
return (long)acc;
8686
}
87-
88-
int32_t atoi(const char *str)
89-
{
90-
return (int32_t)strtol_deci(str);
91-
}

hypervisor/include/lib/rtl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ char *strchr(char *s_arg, char ch);
3838
size_t strnlen_s(const char *str_arg, size_t maxlen_arg);
3939
void *memset(void *base, uint8_t v, size_t n);
4040
void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen);
41-
int32_t atoi(const char *str);
4241
int64_t strtol_deci(const char *nptr);
4342
uint64_t strtoul_hex(const char *nptr);
4443
char *strstr_s(const char *str1, size_t maxlen1,

0 commit comments

Comments
 (0)