examples/fips_validation: ignore \r in input files
[dpdk.git] / examples / fips_validation / fips_validation.c
index 3aaec20..858f581 100644 (file)
@@ -33,6 +33,8 @@ get_file_line(void)
 
                if (loc >= MAX_LINE_CHAR - 1)
                        return -ENOMEM;
+               if (c == '\r')
+                       continue;
                if (c == '\n')
                        break;
                line[loc++] = c;
@@ -281,7 +283,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 +313,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");
@@ -640,6 +650,14 @@ update_info_vec(uint32_t count)
 
        cb = &info.writeback_callbacks[0];
 
+       if (!(strstr(info.vec[0], cb->key))) {
+               fprintf(info.fp_wr, "%s%u\n", cb->key, count);
+               i = 0;
+       } else {
+               snprintf(info.vec[0], strlen(info.vec[0]) + 4, "%s%u", cb->key,
+                               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++) {