tools: acrnctl fix cmd buffer is truncated when vmname too long

'acrnctl start vmname' use a cmd buffer with a sizeof 128 bytes,
cmd[128] buffer will be truncated, when vmnane size is bigger than
29 bytes. In that situation, vmnane size still smaller than
MAX_VM_OS_NAME_LEN, so it should be fixed.
Macro PATH_LEN is useful to determine the cmd[] buffer length, so move
it from acrn_mngr.c into acrn_mngr.h

Tracked-On: #2851
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Reviewed-by: Yan Like <like.yan@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
yuhong.tao@intel.com
2019-03-11 20:56:02 +08:00
committed by wenlingz
parent b2f2d95246
commit 5a7be9b869
4 changed files with 17 additions and 18 deletions

View File

@@ -127,7 +127,7 @@ static void _scan_alive_vm(void)
DIR *dir;
struct dirent *entry;
struct vmmngr_struct *vm;
char name[128];
char name[PATH_LEN];
int pid;
int ret;
@@ -224,8 +224,8 @@ static void _scan_added_vm(void)
DIR *dir;
struct dirent *entry;
struct vmmngr_struct *vm;
char name[128];
char suffix[128];
char name[PATH_LEN];
char suffix[PATH_LEN];
int ret;
ret = check_dir(ACRN_CONF_PATH);
@@ -375,7 +375,7 @@ int list_vm()
int start_vm(const char *vmname)
{
char cmd[128];
char cmd[PATH_LEN + sizeof(ACRN_CONF_PATH_ADD) * 2 + MAX_VM_OS_NAME_LEN * 2];
if (snprintf(cmd, sizeof(cmd), "bash %s/%s.sh $(cat %s/%s.args)",
ACRN_CONF_PATH_ADD, vmname, ACRN_CONF_PATH_ADD, vmname) >= sizeof(cmd)) {