X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Ffips_validation%2Ffips_validation.c;h=52a7bf952d46a73368cb11525d28cb27b5a97865;hb=refs%2Fheads%2Fkvargs-20210924;hp=9bdf257b8b29120ede12d4611375442990d9723c;hpb=2b84d2bd47df6545797ed9841636eb8023c4db7b;p=dpdk.git diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index 9bdf257b8b..52a7bf952d 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -92,6 +92,15 @@ error_exit: return -ENOMEM; } +static void +fips_test_parse_version(void) +{ + int len = strlen(info.vec[0]); + char *ptr = info.vec[0]; + + info.version = strtof(ptr + len - 4, NULL); +} + static int fips_test_parse_header(void) { @@ -106,6 +115,9 @@ fips_test_parse_header(void) if (ret < 0) return ret; + if (info.nb_vec_lines) + fips_test_parse_version(); + for (i = 0; i < info.nb_vec_lines; i++) { if (!algo_parsed) { if (strstr(info.vec[i], "AESVS")) { @@ -281,7 +293,11 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, fips_test_clear(); - strcpy(info.file_name, req_file_path); + if (rte_strscpy(info.file_name, req_file_path, + sizeof(info.file_name)) < 0) { + RTE_LOG(ERR, USER1, "Path %s too long\n", req_file_path); + return -EINVAL; + } info.algo = FIPS_TEST_ALGO_MAX; if (parse_file_type(req_file_path) < 0) { RTE_LOG(ERR, USER1, "File %s type not supported\n", @@ -307,7 +323,11 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, return -ENOMEM; } - strlcpy(info.device_name, device_name, sizeof(info.device_name)); + if (rte_strscpy(info.device_name, device_name, + sizeof(info.device_name)) < 0) { + RTE_LOG(ERR, USER1, "Device name %s too long\n", device_name); + return -EINVAL; + } if (fips_test_parse_header() < 0) { RTE_LOG(ERR, USER1, "Failed parsing header\n"); @@ -344,6 +364,8 @@ fips_test_parse_one_case(void) uint32_t interim_cnt = 0; int ret; + info.vec_start_off = 0; + if (info.interim_callbacks) { for (i = 0; i < info.nb_vec_lines; i++) { is_interim = 0; @@ -365,17 +387,24 @@ fips_test_parse_one_case(void) } } - info.vec_start_off = interim_cnt; - if (interim_cnt) { - for (i = 0; i < interim_cnt; i++) - fprintf(info.fp_wr, "%s\n", info.vec[i]); - fprintf(info.fp_wr, "\n"); - - if (info.nb_vec_lines == interim_cnt) + if (info.version == 21.4f) { + for (i = 0; i < interim_cnt; i++) + fprintf(info.fp_wr, "%s\n", info.vec[i]); + fprintf(info.fp_wr, "\n"); + + if (info.nb_vec_lines == interim_cnt) + return 1; + } else { + for (i = 0; i < info.nb_vec_lines; i++) + fprintf(info.fp_wr, "%s\n", info.vec[i]); + fprintf(info.fp_wr, "\n"); return 1; + } } + info.vec_start_off = interim_cnt; + for (i = info.vec_start_off; i < info.nb_vec_lines; i++) { for (j = 0; info.callbacks[j].key != NULL; j++) if (strstr(info.vec[i], info.callbacks[j].key)) { @@ -621,6 +650,22 @@ parser_read_uint32(uint32_t *value, char *p) return 0; } +int +parser_read_uint16(uint16_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT16_MAX) + return -ERANGE; + + *value = val; + return 0; +} + void parse_write_hex_str(struct fips_val *src) { @@ -640,7 +685,7 @@ update_info_vec(uint32_t count) cb = &info.writeback_callbacks[0]; - if (!(strstr(info.vec[0], cb->key))) { + if ((info.version == 21.4f) && (!(strstr(info.vec[0], cb->key)))) { fprintf(info.fp_wr, "%s%u\n", cb->key, count); i = 0; } else { @@ -648,9 +693,8 @@ update_info_vec(uint32_t count) count); i = 1; } - snprintf(info.vec[0], strlen(info.vec[0]) + 4, "%s%u", cb->key, count); - for (i = 1; i < info.nb_vec_lines; i++) { + for (; i < info.nb_vec_lines; i++) { for (j = 1; info.writeback_callbacks[j].key != NULL; j++) { cb = &info.writeback_callbacks[j]; if (strstr(info.vec[i], cb->key)) {