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:
Shuo A Liu
2018-12-25 10:33:36 +08:00
committed by wenlingz
parent 3e0b06cfd6
commit b3ad44d4c1
14 changed files with 27 additions and 25 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);