mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-18 11:47:30 +00:00
tools: acrnctl: Properly null-terminate cmd_out and buf
Library function strtok_r and printf accept a string with the constraint that the string they receive is properly null-terminated. Signed-off-by: Kaige Fu <kaige.fu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
This commit is contained in:
parent
11abe6e81e
commit
26b089932c
@ -145,6 +145,7 @@ static void vmm_update(void)
|
||||
char *vmname;
|
||||
char *pvmname = NULL;
|
||||
struct vmm_struct *s;
|
||||
size_t len = sizeof(cmd_out);
|
||||
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"find %s/add/ -name \"*.sh\" | "
|
||||
@ -152,6 +153,9 @@ static void vmm_update(void)
|
||||
"sed \"s/.sh//g\"", ACRNCTL_OPT_ROOT);
|
||||
shell_cmd(cmd, cmd_out, sizeof(cmd_out));
|
||||
|
||||
/* Properly null-terminate cmd_out */
|
||||
cmd_out[len - 1] = '\0';
|
||||
|
||||
vmname = strtok_r(cmd_out, "\n", &pvmname);
|
||||
while (vmname) {
|
||||
s = vmm_list_add(vmname);
|
||||
@ -169,6 +173,9 @@ static void vmm_update(void)
|
||||
"sed \"s/-monitor.socket//g\"", ACRN_DM_SOCK_ROOT);
|
||||
shell_cmd(cmd, cmd_out, sizeof(cmd_out));
|
||||
|
||||
/* Properly null-terminate cmd_out */
|
||||
cmd_out[len - 1] = '\0';
|
||||
|
||||
vmname = strtok_r(cmd_out, "\n", &pvmname);
|
||||
while (vmname) {
|
||||
s = vmm_find(vmname);
|
||||
@ -314,6 +321,7 @@ static int acrnctl_do_add(int argc, char *argv[])
|
||||
int p, i;
|
||||
char cmd_out[256];
|
||||
char vmname[128];
|
||||
size_t len = sizeof(cmd_out);
|
||||
|
||||
if (argc < 2) {
|
||||
acrnctl_add_help();
|
||||
@ -375,6 +383,9 @@ static int acrnctl_do_add(int argc, char *argv[])
|
||||
|
||||
find_acrn_dm = 0;
|
||||
|
||||
/* Properly null-terminate buf */
|
||||
buf[MAX_FILE_SIZE - 1] = '\0';
|
||||
|
||||
line = strtok_r(buf, "\n", &line_p);
|
||||
while (line) {
|
||||
word_p = NULL;
|
||||
@ -423,6 +434,10 @@ static int acrnctl_do_add(int argc, char *argv[])
|
||||
ret = -1;
|
||||
snprintf(cmd, sizeof(cmd), "cat ./%s.result", argv[1]);
|
||||
shell_cmd(cmd, cmd_out, sizeof(cmd_out));
|
||||
|
||||
/* Properly null-terminate cmd_out */
|
||||
cmd_out[len - 1] = '\0';
|
||||
|
||||
printf("%s can't reach acrn-dm, "
|
||||
"please try again when you make sure it can launch an UOS\n"
|
||||
"result:\n%s\n", argv[1], cmd_out);
|
||||
|
Loading…
Reference in New Issue
Block a user