mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-24 22:42:53 +00:00
dm: use strnlen to replace strlen
Tracked-On: #2133 Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com> Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
This commit is contained in:
parent
ff2ed240a0
commit
0bb20c3812
@ -157,7 +157,7 @@ static int open_hugetlbfs(struct vmctx *ctx, int level)
|
||||
UUID[12], UUID[13], UUID[14], UUID[15]);
|
||||
|
||||
*(path + len) = '\0';
|
||||
strncat(path, uuid_str, strlen(uuid_str));
|
||||
strncat(path, uuid_str, strnlen(uuid_str, sizeof(uuid_str)));
|
||||
|
||||
printf("open hugetlbfs file %s\n", path);
|
||||
|
||||
@ -347,19 +347,19 @@ static int create_hugetlb_dirs(int level)
|
||||
}
|
||||
|
||||
path = hugetlb_priv[level].mount_path;
|
||||
len = strlen(path);
|
||||
if (len >= MAX_PATH_LEN || len == 0) {
|
||||
len = strnlen(path, MAX_PATH_LEN);
|
||||
if (len == MAX_PATH_LEN || len == 0) {
|
||||
perror("invalid path len");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memset(tmp_path, '\0', MAX_PATH_LEN);
|
||||
strncpy(tmp_path, path, MAX_PATH_LEN - 1);
|
||||
strncpy(tmp_path, path, MAX_PATH_LEN);
|
||||
|
||||
if ((tmp_path[len - 1] != '/') && (strlen(tmp_path) < MAX_PATH_LEN - 1))
|
||||
strcat(tmp_path, "/");
|
||||
if ((tmp_path[len - 1] != '/') && (len < MAX_PATH_LEN - 1))
|
||||
tmp_path[len] = '/';
|
||||
|
||||
len = strlen(tmp_path);
|
||||
len = strnlen(tmp_path, MAX_PATH_LEN);
|
||||
for (i = 1; i < len; i++) {
|
||||
if (tmp_path[i] == '/') {
|
||||
tmp_path[i] = 0;
|
||||
|
@ -165,8 +165,8 @@ usage(int code)
|
||||
" --intr_monitor: enable interrupt storm monitor\n"
|
||||
" --vtpm2: Virtual TPM2 args: sock_path=$PATH_OF_SWTPM_SOCKET\n"
|
||||
"............its params: threshold/s,probe-period(s),delay_time(ms),delay_duration(ms)\n",
|
||||
progname, (int)strlen(progname), "", (int)strlen(progname), "",
|
||||
(int)strlen(progname), "");
|
||||
progname, (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "",
|
||||
(int)strnlen(progname, PATH_MAX), "");
|
||||
|
||||
exit(code);
|
||||
}
|
||||
|
@ -544,7 +544,7 @@ smbios_generic_initializer(struct smbios_structure *template_entry,
|
||||
int len;
|
||||
|
||||
string = template_strings[i];
|
||||
len = strlen(string) + 1;
|
||||
len = strnlen(string, SMBIOS_MAX_LENGTH) + 1;
|
||||
memcpy(curaddr, string, len);
|
||||
curaddr += len;
|
||||
}
|
||||
@ -597,7 +597,7 @@ smbios_type1_initializer(struct smbios_structure *template_entry,
|
||||
return -1;
|
||||
|
||||
MD5_Init(&mdctx);
|
||||
MD5_Update(&mdctx, vmname, strlen(vmname));
|
||||
MD5_Update(&mdctx, vmname, strnlen(vmname, PATH_MAX));
|
||||
MD5_Update(&mdctx, hostname, sizeof(hostname));
|
||||
MD5_Final(digest, &mdctx);
|
||||
|
||||
|
@ -129,7 +129,7 @@ acrn_get_bzimage_setup_size(struct vmctx *ctx)
|
||||
int
|
||||
acrn_parse_kernel(char *arg)
|
||||
{
|
||||
size_t len = strlen(arg);
|
||||
size_t len = strnlen(arg, STR_LEN);
|
||||
|
||||
if (len < STR_LEN) {
|
||||
strncpy(kernel_path, arg, len + 1);
|
||||
@ -150,7 +150,7 @@ acrn_parse_kernel(char *arg)
|
||||
int
|
||||
acrn_parse_ramdisk(char *arg)
|
||||
{
|
||||
size_t len = strlen(arg);
|
||||
size_t len = strnlen(arg, STR_LEN);
|
||||
|
||||
if (len < STR_LEN) {
|
||||
strncpy(ramdisk_path, arg, len + 1);
|
||||
|
@ -99,7 +99,7 @@ const struct e820_entry e820_default_entries[NUM_E820_ENTRIES] = {
|
||||
int
|
||||
acrn_parse_bootargs(char *arg)
|
||||
{
|
||||
size_t len = strlen(arg);
|
||||
size_t len = strnlen(arg, STR_LEN);
|
||||
|
||||
if (len < STR_LEN) {
|
||||
strncpy(bootargs, arg, len + 1);
|
||||
|
@ -70,7 +70,7 @@ int
|
||||
acrn_parse_ovmf(char *arg)
|
||||
{
|
||||
int error;
|
||||
size_t len = strlen(arg);
|
||||
size_t len = strnlen(arg, STR_LEN);
|
||||
|
||||
if (len < STR_LEN) {
|
||||
strncpy(ovmf_path, arg, len + 1);
|
||||
|
@ -126,7 +126,7 @@ int
|
||||
acrn_parse_guest_part_info(char *arg)
|
||||
{
|
||||
int error;
|
||||
size_t len = strlen(arg);
|
||||
size_t len = strnlen(arg, STR_LEN);
|
||||
|
||||
if (len < STR_LEN) {
|
||||
strncpy(guest_part_info_path, arg, len + 1);
|
||||
@ -195,7 +195,7 @@ int
|
||||
acrn_parse_vsbl(char *arg)
|
||||
{
|
||||
int error;
|
||||
size_t len = strlen(arg);
|
||||
size_t len = strnlen(arg, STR_LEN);
|
||||
|
||||
if (len < STR_LEN) {
|
||||
strncpy(vsbl_path, arg, len + 1);
|
||||
|
@ -93,7 +93,7 @@ vm_create(const char *name, uint64_t req_buf)
|
||||
uuid_t vm_uuid;
|
||||
|
||||
memset(&create_vm, 0, sizeof(struct acrn_create_vm));
|
||||
ctx = calloc(1, sizeof(struct vmctx) + strlen(name) + 1);
|
||||
ctx = calloc(1, sizeof(struct vmctx) + strnlen(name, PATH_MAX) + 1);
|
||||
assert(ctx != NULL);
|
||||
assert(devfd == -1);
|
||||
|
||||
|
@ -823,7 +823,7 @@ virtio_net_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
||||
dev->func, mac_seed);
|
||||
|
||||
MD5_Init(&mdctx);
|
||||
MD5_Update(&mdctx, nstr, strlen(nstr));
|
||||
MD5_Update(&mdctx, nstr, strnlen(nstr, sizeof(nstr)));
|
||||
MD5_Final(digest, &mdctx);
|
||||
|
||||
net->config.mac[0] = 0x00;
|
||||
|
@ -501,6 +501,7 @@ static int pci_xhci_parse_log_level(struct pci_xhci_vdev *xdev, char *opts);
|
||||
static int pci_xhci_parse_extcap(struct pci_xhci_vdev *xdev, char *opts);
|
||||
static int pci_xhci_convert_speed(int lspeed);
|
||||
|
||||
#define XHCI_OPT_MAX_LEN 32
|
||||
static struct pci_xhci_option_elem xhci_option_table[] = {
|
||||
{"tablet", pci_xhci_parse_tablet},
|
||||
{"log", pci_xhci_parse_log_level},
|
||||
@ -3985,7 +3986,7 @@ pci_xhci_parse_opts(struct pci_xhci_vdev *xdev, char *opts)
|
||||
if (!n || !f)
|
||||
continue;
|
||||
|
||||
if (!strncmp(t, n, strlen(n))) {
|
||||
if (!strncmp(t, n, strnlen(n, XHCI_OPT_MAX_LEN))) {
|
||||
f(xdev, t);
|
||||
break;
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ static int rpmb_check_frame(const char *cmd_str, int *err,
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = strlen(cmd_str) + 1;
|
||||
len = strnlen(cmd_str, sizeof(WRITE_DATA_STR)) + 1;
|
||||
if (len > sizeof(WRITE_DATA_STR))
|
||||
len = sizeof(WRITE_DATA_STR);
|
||||
|
||||
|
@ -37,9 +37,9 @@ char *const token[] = {
|
||||
int acrn_parse_vtpm2(char *arg)
|
||||
{
|
||||
char *value;
|
||||
size_t len = strlen(arg);
|
||||
size_t len = strnlen(arg, STR_MAX_LEN);
|
||||
|
||||
if (len > STR_MAX_LEN)
|
||||
if (len == STR_MAX_LEN)
|
||||
return -1;
|
||||
|
||||
if (SOCK_PATH_OPT == getsubopt(&arg, token, &value)) {
|
||||
|
@ -217,7 +217,7 @@ static int ctrl_chan_conn(const char *servername)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strlen(servername) > (sizeof(servaddr.sun_path) -1)) {
|
||||
if (strnlen(servername, sizeof(servaddr.sun_path)) == (sizeof(servaddr.sun_path))) {
|
||||
printf("%s error, length of servername is too long\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ enum {
|
||||
UMSTR_MAX
|
||||
};
|
||||
|
||||
#define UMOUSE_DESC_MAX_LEN 32
|
||||
static const char *const umouse_desc_strings[] = {
|
||||
"\x04\x09",
|
||||
"ACRN-DM",
|
||||
@ -437,7 +438,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer)
|
||||
goto done;
|
||||
}
|
||||
|
||||
slen = 2 + strlen(str) * 2;
|
||||
slen = 2 + strnlen(str, UMOUSE_DESC_MAX_LEN) * 2;
|
||||
udata[0] = slen;
|
||||
udata[1] = UDESC_STRING;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user