tools: acrnctl restrict length of vmname to 32 bytes

When run 'acrnctl add launch_script.sh', vmname will be detected from
the launch script and stored in vmmngr_struct.name[MAX_VM_OS_NAME_LEN],
so vmname should not be longer than MAX_VM_OS_NAME_LEN.

Tracked-On: #2851
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
yuhong.tao@intel.com 2019-03-11 20:02:48 +08:00 committed by wenlingz
parent 8109c2e94c
commit b2f2d95246
4 changed files with 13 additions and 8 deletions

View File

@ -7,9 +7,9 @@
#define ACRN_MANAGER_H
#include <stdlib.h>
#include <acrn_common.h>
#define MNGR_MSG_MAGIC 0x67736d206d6d76 /* that is char[8] "mngr msg", on X86 */
#define VMNAME_LEN 16
struct mngr_msg {
unsigned long long magic; /* Make sure you get a mngr_msg */
@ -28,7 +28,7 @@ struct mngr_msg {
/* req of ACRND_TIMER */
struct req_acrnd_timer {
char name[VMNAME_LEN];
char name[MAX_VM_OS_NAME_LEN];
time_t t;
} acrnd_timer;
@ -52,7 +52,7 @@ struct mngr_msg {
/* req of RTC_TIMER */
struct req_rtc_timer {
char vmname[VMNAME_LEN];
char vmname[MAX_VM_OS_NAME_LEN];
time_t t;
} rtc_timer;

View File

@ -85,6 +85,11 @@ static int check_name(const char *name)
if (!strcmp(name, "nothing"))
return -1;
if (strnlen(name, MAX_VM_OS_NAME_LEN) >= MAX_VM_OS_NAME_LEN) {
printf("(%s) size exceed MAX_VM_OS_NAME_LEN:%u\n", name,MAX_VM_OS_NAME_LEN);
return -1;
}
return 0;
}

View File

@ -7,6 +7,8 @@
#define _ACRNCTL_H_
#include <sys/queue.h>
#include <acrn_common.h>
#include "acrn_mngr.h"
#define ACRN_CONF_PATH "/usr/share/acrn/conf"
#define ACRN_CONF_PATH_ADD ACRN_CONF_PATH "/add"
@ -14,8 +16,6 @@
#define ACRN_DM_SOCK_PATH "/run/acrn/mngr"
#define MAX_NAME_LEN (32)
enum vm_state {
VM_STATE_UNKNOWN = 0,
VM_CREATED, /* VM created / awaiting start (boot) */
@ -36,7 +36,7 @@ struct vmmngr_struct *vmmngr_find(const char *vmname);
/* Per-vm vm managerment struct */
struct vmmngr_struct {
char name[MAX_NAME_LEN];
char name[MAX_VM_OS_NAME_LEN];
unsigned long state;
unsigned long state_tmp;
unsigned long update; /* update count, remove a vm if no update for it */

View File

@ -23,7 +23,7 @@
/* acrnd worker timer */
struct work_arg {
char name[VMNAME_LEN];
char name[MAX_VM_OS_NAME_LEN];
};
struct acrnd_work {
@ -356,7 +356,7 @@ static void handle_timer_req(struct mngr_msg *msg, int client_fd, void *param)
}
strncpy(arg.name, msg->data.acrnd_timer.name, sizeof(arg.name) - 1);
if (sizeof(arg.name) - 1 < strnlen(msg->data.acrnd_timer.name, VMNAME_LEN)) {
if (sizeof(arg.name) - 1 < strnlen(msg->data.acrnd_timer.name, MAX_VM_OS_NAME_LEN)) {
perror("timer name was truncated\n");
goto reply_ack;
}