Commit 25a05e82 authored by Robert Schmidt's avatar Robert Schmidt

Correctly use strncpy()/strncat()

parent 31bd2249
......@@ -407,7 +407,8 @@ static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *
if (ant_num >= MAX_ANT_CARRIER_SUPPORTED) {
printf("antC%d exceeds max antenna supported\n",ant_num);
} else {
strncpy(&config->ant_file[ant_num][0], value, strlen(value));
strncpy(&config->ant_file[ant_num][0], value, 512);
config->ant_file[ant_num][511] = 0;
printf("antC%d: %s\n",ant_num, config->ant_file[ant_num]);
}
} else if (strncmp(key, KEY_FILE_DLBFWUE, strlen(KEY_FILE_DLBFWUE)) == 0) {
......@@ -416,7 +417,8 @@ static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *
if (ue_num >= MAX_ANT_CARRIER_SUPPORTED) {
printf("DlBfwUe%d exceeds max streams supported\n",ue_num);
} else {
strncpy(&config->dl_bfw_file[ue_num][0], value, strlen(value));
strncpy(&config->dl_bfw_file[ue_num][0], value, 512);
config->dl_bfw_file[ue_num][511] = 0;
printf("DlBfwUe%d: %s\n",ue_num, config->dl_bfw_file[ue_num]);
}
}else if (strncmp(key, KEY_FILE_ULBFWUE, strlen(KEY_FILE_ULBFWUE)) == 0) {
......@@ -425,7 +427,8 @@ static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *
if (ue_num >= MAX_ANT_CARRIER_SUPPORTED) {
printf("UlBfwUe%d exceeds max streams supported\n",ue_num);
} else {
strncpy(&config->ul_bfw_file[ue_num][0], value, strlen(value));
strncpy(&config->ul_bfw_file[ue_num][0], value, 512);
config->ul_bfw_file[ue_num][511] = 0;
printf("UlBfwUe%d: %s\n",ue_num, config->ul_bfw_file[ue_num]);
}
}else if (strncmp(key, KEY_FILE_ULSRS, strlen(KEY_FILE_ULSRS)) == 0) {
......@@ -434,7 +437,8 @@ static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *
if (srs_ant >= MAX_ANT_CARRIER_SUPPORTED_CAT_B) {
printf("antSrsC%d exceeds max ant elemnets supported [%d]\n", srs_ant, MAX_ANT_CARRIER_SUPPORTED_CAT_B);
} else {
strncpy(&config->ul_srs_file[srs_ant][0], value, strlen(value));
strncpy(&config->ul_srs_file[srs_ant][0], value, 512);
config->ul_srs_file[srs_ant][511] = 0;
printf("antSrsC%d: %s\n",srs_ant, config->ul_srs_file[srs_ant]);
}
} else if (strncmp(key, KEY_FILE_SLOT_TX, strlen(KEY_FILE_SLOT_TX)) == 0) {
......@@ -445,7 +449,8 @@ static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *
printf("SlotNumTx%d exceeds max slots supported\n",slot_num);
} else {
config->SlotNum_fileEnabled = 1;
strncpy(&config->SlotNum_file[direction][slot_num][0], value, strlen(value));
strncpy(&config->SlotNum_file[direction][slot_num][0], value, 512);
config->SlotNum_file[direction][slot_num][511] = 0;
printf("SlotNumTx%d: %s\n",slot_num, config->SlotNum_file[direction][slot_num]);
}
}else if (strncmp(key, KEY_FILE_SLOT_RX, strlen(KEY_FILE_SLOT_RX)) == 0) {
......@@ -456,7 +461,8 @@ static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *
printf("SlotNumRx%d exceeds max slots supported\n",slot_num);
} else {
config->SlotNum_fileEnabled = 1;
strncpy(&config->SlotNum_file[direction][slot_num][0], value, strlen(value));
strncpy(&config->SlotNum_file[direction][slot_num][0], value, 512);
config->SlotNum_file[direction][slot_num][511] = 0;
printf("SlotNumRx%d: %s\n",slot_num, config->SlotNum_file[direction][slot_num]);
}
} else if (strcmp(key, KEY_PRACH_ENABLE) == 0) {
......@@ -494,7 +500,8 @@ static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *
printf("antC%d exceeds max antenna supported\n",ant_num);
}
else{
strncpy(&config->prach_file[ant_num][0], value, strlen(value));
strncpy(&config->prach_file[ant_num][0], value, 512);
config->prach_file[ant_num][511] = 0;
printf("antPrachC%d: %s\n",ant_num, config->prach_file[ant_num]);
}
} else if (strcmp(key, KEY_BFW_NUM) == 0) {
......@@ -772,7 +779,8 @@ fillUsecaseStruct(UsecaseConfig *config, const char *key, const char *value)
if (o_xu_id >= XRAN_PORTS_NUM) {
printf("oXuCfgFile%d exceeds max O-XU supported\n",o_xu_id);
} else {
strncpy(&config->o_xu_cfg_file[o_xu_id][0], value, strlen(value));
strncpy(&config->o_xu_cfg_file[o_xu_id][0], value, 512);
config->o_xu_cfg_file[o_xu_id][511] = 0;
printf("oXuCfgFile%d: %s\n",o_xu_id, config->o_xu_cfg_file[o_xu_id]);
}
} else if (strncmp(key, KEY_OWDM_INIT_EN, strlen(KEY_OWDM_INIT_EN)) == 0) {
......@@ -809,7 +817,8 @@ fillUsecaseStruct(UsecaseConfig *config, const char *key, const char *value)
if (o_xu_id >= XRAN_PORTS_NUM || vf_num >= XRAN_VF_MAX){
printf("PciBusAddoXu%dVf%d exceeds max O-XU supported\n",o_xu_id, vf_num);
} else {
strncpy(&config->o_xu_pcie_bus_addr[o_xu_id][vf_num][0], value, strlen(value));
strncpy(&config->o_xu_pcie_bus_addr[o_xu_id][vf_num][0], value, 512);
config->o_xu_pcie_bus_addr[o_xu_id][vf_num][511] = 0;
printf("PciBusAddoXu%dVf%d: %s\n",o_xu_id, vf_num, &config->o_xu_pcie_bus_addr[o_xu_id][vf_num][0]);
}
} else if (strncmp(key, KEY_O_XU_REM_MAC, strlen(KEY_O_XU_REM_MAC)) == 0) {
......@@ -1138,14 +1147,16 @@ parseSlotConfigFile(char *dir, RuntimeConfig *config)
printf("parseSlotConfigFile: Name of directory, %s is too long. Maximum is 511 characters!!\n", dir);
return -1;
} else {
strncpy(filename, dir, len);
strncpy(filename, dir, sizeof(filename));
filename[sizeof(filename) - 1] = 0;
}
strncat(filename, "/", 1);
len +=1;
len = (sizeof(filename)) - len;
if(len > strlen(config->SlotNum_file[direction][slot_idx])){
strncat(filename, config->SlotNum_file[direction][slot_idx], RTE_MIN (len, strlen(config->SlotNum_file[direction][slot_idx])));
strncat(filename, config->SlotNum_file[direction][slot_idx], sizeof(filename) - 1);
filename[sizeof(filename) - 1] = 0;
} else {
printf("File name error\n");
return -1;
......
......@@ -369,7 +369,8 @@ app_parse_all_cfgs(struct sample_app_params* p_args, UsecaseConfig* p_use_cfg,
printf("app_parse_all_cfgs: Name of p_args->usecase_file, %s is too long. Maximum is 511 characters!!\n", p_args->usecase_file);
return -1;
} else {
strncpy(filename, p_args->usecase_file, len);
strncpy(filename, p_args->usecase_file, 512);
filename[511] = 0;
}
if (parseUsecaseFile(filename, p_use_cfg) != 0) {
printf("Use case config file error.\n");
......@@ -383,7 +384,8 @@ app_parse_all_cfgs(struct sample_app_params* p_args, UsecaseConfig* p_use_cfg,
/* use cmdline pcie address */
for (o_xu_id = 0; o_xu_id < p_use_cfg->oXuNum && o_xu_id < XRAN_PORTS_NUM; o_xu_id++) {
for (vf_num = 0; vf_num < XRAN_VF_MAX && p_args->num_vfs ; vf_num++) {
strncpy(&p_use_cfg->o_xu_pcie_bus_addr[o_xu_id][vf_num][0], &p_args->vf_pcie_addr[o_xu_id][vf_num][0], strlen(&p_args->vf_pcie_addr[o_xu_id][vf_num][0]));
strncpy(&p_use_cfg->o_xu_pcie_bus_addr[o_xu_id][vf_num][0], &p_args->vf_pcie_addr[o_xu_id][vf_num][0], 512);
p_use_cfg->o_xu_pcie_bus_addr[o_xu_id][vf_num][511] = 0;
}
}
dir = dirname(p_args->usecase_file);
......@@ -395,14 +397,16 @@ app_parse_all_cfgs(struct sample_app_params* p_args, UsecaseConfig* p_use_cfg,
printf("app_parse_all_cfgs: Name of directory, %s, xu_id = %d is too long. Maximum is 511 characters!!\n", dir, o_xu_id);
return -1;
} else {
strncpy(filename, dir, len);
strncpy(filename, dir, 512);
filename[511] = 0;
}
strncat(filename, "/", 1);
len +=1;
len = (sizeof(filename)) - len;
if (len > strlen(p_use_cfg->o_xu_cfg_file[o_xu_id])) {
strncat(filename, p_use_cfg->o_xu_cfg_file[o_xu_id], RTE_MIN (len, strlen(p_use_cfg->o_xu_cfg_file[o_xu_id])));
strncat(filename, p_use_cfg->o_xu_cfg_file[o_xu_id], RTE_MIN (len, sizeof(filename)));
filename[511] = 0;
} else {
printf("File name error\n");
return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment