VNFs: Fixing klocwork issue in VNFs code 07/44507/1
authorAnand B Jyoti <anand.b.jyoti@intel.com>
Wed, 4 Oct 2017 04:45:40 +0000 (10:15 +0530)
committerDeepak S <deepak.s@linux.intel.com>
Sat, 7 Oct 2017 00:41:15 +0000 (17:41 -0700)
JIRA: SAMPLEVNF-83

This patch fixes the klocwork reported issues

Change-Id: I190d024777be1bf53cdc97feca1e5934781f3582
Signed-off-by: Anand B Jyoti <anand.b.jyoti@intel.com>
VNFs/UDP_Replay/main.c
VNFs/vACL/init.c
VNFs/vACL/pipeline/pipeline_acl_be.c
VNFs/vACL/pipeline/pipeline_acl_be.h
VNFs/vCGNAPT/init.c
VNFs/vCGNAPT/pipeline/pipeline_cgnapt_be.c
VNFs/vFW/init.c
VNFs/vFW/pipeline/pipeline_vfw_be.c

index 587057f..2830aa4 100644 (file)
@@ -1993,6 +1993,7 @@ main_loop(__attribute__((unused)) void *dummy)
 #endif /* ENABLE_MULTI_BUFFER_OPTIMIZE */
                }
        }
+       return 0;
 }
 
 /* display usage */
index dda6277..b83825b 100644 (file)
@@ -100,14 +100,20 @@ app_init_eal(struct app_params *app)
        uint32_t i;
        int status;
 
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(app->app_name);
 
        app_core_build_core_mask_string(app, core_mask_str);
        snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(buffer);
 
        if (p->coremap) {
                snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -116,19 +122,27 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--master-lcore=%" PRIu32,
                        p->master_lcore);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(buffer);
 
        if (p->memory_present) {
                snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->ranks_present) {
                snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -140,6 +154,8 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--pci-blacklist=%s",
                        p->pci_blacklist[i]);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -163,6 +179,8 @@ app_init_eal(struct app_params *app)
                                sizeof(buffer),
                                "--pci-whitelist=%s",
                                pci_bdf);
+                       if (unlikely (n_args >= APP_EAL_ARGC))
+                               goto error_exit;
                        app->eal_argv[n_args++] = strdup(buffer);
                }
 
@@ -174,11 +192,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--vdev=%s",
                        p->vdev[i]);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
                snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -187,11 +209,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--proc-type=%s",
                        p->proc_type);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->syslog) {
                snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -200,41 +226,57 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--log-level=%" PRIu32,
                        p->log_level);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->version_present) && p->version) {
                snprintf(buffer, sizeof(buffer), "-v");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->help_present) && p->help) {
                snprintf(buffer, sizeof(buffer), "--help");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_huge_present) && p->no_huge) {
                snprintf(buffer, sizeof(buffer), "--no-huge");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_pci_present) && p->no_pci) {
                snprintf(buffer, sizeof(buffer), "--no-pci");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_hpet_present) && p->no_hpet) {
                snprintf(buffer, sizeof(buffer), "--no-hpet");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_shconf_present) && p->no_shconf) {
                snprintf(buffer, sizeof(buffer), "--no-shconf");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->add_driver) {
                snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -243,11 +285,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--socket-mem=%s",
                        p->socket_mem);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->huge_dir) {
                snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -256,6 +302,8 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--file-prefix=%s",
                        p->file_prefix);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -264,11 +312,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--base-virtaddr=%s",
                        p->base_virtaddr);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->create_uio_dev_present) && p->create_uio_dev) {
                snprintf(buffer, sizeof(buffer), "--create-uio-dev");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -277,15 +329,21 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--vfio-intr=%s",
                        p->vfio_intr);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->xen_dom0_present) && (p->xen_dom0)) {
                snprintf(buffer, sizeof(buffer), "--xen-dom0");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        snprintf(buffer, sizeof(buffer), "--");
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(buffer);
 
        app->eal_argc = n_args;
@@ -301,8 +359,10 @@ app_init_eal(struct app_params *app)
        }
 
        status = rte_eal_init(app->eal_argc, app->eal_argv);
-       if (status < 0)
+       if (status < 0) {
+error_exit:
                rte_panic("EAL init error\n");
+       }
 }
 
 static inline int
@@ -536,7 +596,7 @@ app_link_up_internal(struct app_params *app, struct app_link_params *cp)
        struct rte_eth_link link;
 
         if(app == NULL || cp == NULL)
-                printf("NULL Pointers");
+               rte_panic("NULL Pointers");
 
 #if RTE_VERSION < 0x100b0000
        if (app_link_is_virtual(cp)) {
@@ -559,7 +619,7 @@ app_link_down_internal(struct app_params *app, struct app_link_params *cp)
        struct rte_eth_link link;
 
         if(app == NULL || cp == NULL)
-                printf("NULL Pointers");
+                rte_panic("NULL Pointers");
 
 #if RTE_VERSION < 0x100b0000
        if (app_link_is_virtual(cp)) {
index d3fa051..512c2f6 100644 (file)
@@ -2638,7 +2638,7 @@ static void *pipeline_acl_init(struct pipeline_params *params,
        if (p == NULL)
                return NULL;
 
-       strcpy(p->name, params->name);
+       strncpy(p->name, params->name, PIPELINE_NAME_SIZE);
        p->log_level = params->log_level;
 
        PLOG(p, HIGH, "ACL");
@@ -2681,7 +2681,7 @@ static void *pipeline_acl_init(struct pipeline_params *params,
 
        rte_ACL_hi_counter_block_in_use++;
        counter_ptr = &rte_acl_counter_table[rte_ACL_hi_counter_block_in_use];
-       strcpy(counter_ptr->name, params->name);
+       strncpy(counter_ptr->name, params->name,PIPELINE_NAME_SIZE);
        p_acl->action_counter_index = rte_ACL_hi_counter_block_in_use;
 
        p_acl->counters = counter_ptr;
index bbb20e8..edce7e4 100644 (file)
@@ -64,7 +64,7 @@ extern uint8_t ACL_DEBUG;
  * One counter block per ACL Thread
  */
 struct rte_ACL_counter_block {
-       char name[32];
+       char name[PIPELINE_NAME_SIZE];
        /* as long as a counter doesn't cross cache line, writes are atomic */
        uint64_t tpkts_processed;
        uint64_t bytes_processed;       /* includes all L3 and higher headers */
index d61e419..2716f75 100644 (file)
@@ -98,14 +98,20 @@ app_init_eal(struct app_params *app)
        uint32_t i;
        int status;
 
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(app->app_name);
 
        app_core_build_core_mask_string(app, core_mask_str);
        snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(buffer);
 
        if (p->coremap) {
                snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -114,19 +120,27 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--master-lcore=%" PRIu32,
                        p->master_lcore);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(buffer);
 
        if (p->memory_present) {
                snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->ranks_present) {
                snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -138,6 +152,8 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--pci-blacklist=%s",
                        p->pci_blacklist[i]);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -150,8 +166,10 @@ app_init_eal(struct app_params *app)
                                sizeof(buffer),
                                "--pci-whitelist=%s",
                                p->pci_whitelist[i]);
+                       if (unlikely (n_args >= APP_EAL_ARGC))
+                               goto error_exit;
                        if (n_args < 255)
-                       app->eal_argv[n_args++] = strdup(buffer);
+                               app->eal_argv[n_args++] = strdup(buffer);
                }
        else
                for (i = 0; i < app->n_links; i++) {
@@ -161,6 +179,8 @@ app_init_eal(struct app_params *app)
                                sizeof(buffer),
                                "--pci-whitelist=%s",
                                pci_bdf);
+                       if (unlikely (n_args >= APP_EAL_ARGC))
+                               goto error_exit;
                        app->eal_argv[n_args++] = strdup(buffer);
                }
 
@@ -172,11 +192,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--vdev=%s",
                        p->vdev[i]);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
                snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -185,11 +209,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--proc-type=%s",
                        p->proc_type);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->syslog) {
                snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -198,41 +226,57 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--log-level=%" PRIu32,
                        p->log_level);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->version_present) && p->version) {
                snprintf(buffer, sizeof(buffer), "-v");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->help_present) && p->help) {
                snprintf(buffer, sizeof(buffer), "--help");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_huge_present) && p->no_huge) {
                snprintf(buffer, sizeof(buffer), "--no-huge");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_pci_present) && p->no_pci) {
                snprintf(buffer, sizeof(buffer), "--no-pci");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_hpet_present) && p->no_hpet) {
                snprintf(buffer, sizeof(buffer), "--no-hpet");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_shconf_present) && p->no_shconf) {
                snprintf(buffer, sizeof(buffer), "--no-shconf");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->add_driver) {
                snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -241,11 +285,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--socket-mem=%s",
                        p->socket_mem);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->huge_dir) {
                snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -254,6 +302,8 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--file-prefix=%s",
                        p->file_prefix);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -262,11 +312,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--base-virtaddr=%s",
                        p->base_virtaddr);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->create_uio_dev_present) && p->create_uio_dev) {
                snprintf(buffer, sizeof(buffer), "--create-uio-dev");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -275,15 +329,21 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--vfio-intr=%s",
                        p->vfio_intr);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->xen_dom0_present) && (p->xen_dom0)) {
                snprintf(buffer, sizeof(buffer), "--xen-dom0");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        snprintf(buffer, sizeof(buffer), "--");
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(buffer);
 
        app->eal_argc = n_args;
@@ -299,8 +359,10 @@ app_init_eal(struct app_params *app)
        }
 
        status = rte_eal_init(app->eal_argc, app->eal_argv);
-       if (status < 0)
+       if (status < 0) {
+error_exit:
                rte_panic("EAL init error\n");
+       }
 }
 #if 0
 static void
index 7758c5b..a1779aa 100644 (file)
@@ -2235,7 +2235,7 @@ static int cgnapt_in_port_ah_mix(struct rte_pipeline *rte_p,
                                *outport_id = p_nat->outport_id[dest_if];
 
                                ret_arp_data = get_dest_mac_addr_ipv4(nhip,
-                                               dest_if, (struct ether_addr *)eth_dest);
+                                               dest_if, (struct ether_addr *)&hw_addr);
 
                                if (unlikely(ret_arp_data == NULL)) {
 
@@ -3695,6 +3695,12 @@ pkt_work_cgnapt_ipv4_prv(
                src_port = RTE_MBUF_METADATA_UINT16_PTR(pkt, src_port_offset);
                dst_port = RTE_MBUF_METADATA_UINT16_PTR(pkt, dst_port_offset);
        break;
+       default: /* KW fix: unknown is treated as TCP/UDP */
+               src_port_offset = SRC_PRT_OFST_IP4_TCP;
+               dst_port_offset = DST_PRT_OFST_IP4_TCP;
+               src_port = RTE_MBUF_METADATA_UINT16_PTR(pkt, src_port_offset);
+               dst_port = RTE_MBUF_METADATA_UINT16_PTR(pkt, dst_port_offset);
+       break;
        }
 
        uint8_t *eth_dest = RTE_MBUF_METADATA_UINT8_PTR(pkt, MBUF_HDR_ROOM);
@@ -4481,6 +4487,14 @@ pkt4_work_cgnapt_ipv4_prv(
                        dst_port = RTE_MBUF_METADATA_UINT16_PTR(pkt,
                                        dst_port_offset);
                break;
+               default: /* KW fix: unknown is treated as TCP/UDP */
+                       src_port_offset = SRC_PRT_OFST_IP4_TCP;
+                       dst_port_offset = DST_PRT_OFST_IP4_TCP;
+                       src_port = RTE_MBUF_METADATA_UINT16_PTR(pkt,
+                                       src_port_offset);
+                       dst_port = RTE_MBUF_METADATA_UINT16_PTR(pkt,
+                                       dst_port_offset);
+               break;
                }
 
 
@@ -8107,7 +8121,7 @@ static void *pipeline_cgnapt_init(struct pipeline_params *params, void *arg)
 
        all_pipeline_cgnapt[n_cgnapt_pipeline++] = p_nat;
 
-       strcpy(p->name, params->name);
+       strncpy(p->name, params->name,PIPELINE_NAME_SIZE);
        p->log_level = params->log_level;
 
        PLOG(p, HIGH, "CG-NAPT");
@@ -10502,7 +10516,7 @@ void all_cgnapt_stats(char *buf)
                len += sprintf(buf + len, "egress %" PRIu64 "\n", p_nat->enaptedPktCount);
                len += sprintf(buf + len, "arpicmp pkts %" PRIu64 "\n", p_nat->arpicmpPktCount);
 
-       printf("\nCG-NAPT Packet Stats:\n");
+               printf("\nCG-NAPT Packet Stats:\n");
                printf("pipeline %d stats:\n", p_nat->pipeline_num);
                printf("Received %" PRIu64 ",", p_nat->receivedPktCount);
                printf("Missed %" PRIu64 ",", p_nat->missedPktCount);
@@ -10557,7 +10571,7 @@ void all_cgnapt_stats(char *buf)
        len += sprintf(buf + len, "egress %" PRIu64 "\n", enaptedPktCount);
        len += sprintf(buf + len, "arpicmp pkts %" PRIu64 "\n", arpicmpPktCount);
 
- printf("\nTotal pipeline stats:\n");
      printf("\nTotal pipeline stats:\n");
        printf("Received %" PRIu64 ",", receivedPktCount);
        printf("Missed %" PRIu64 ",", missedPktCount);
        printf("Dropped %" PRIu64 ",",  naptDroppedPktCount);
index 0edc5e3..c3d4a6c 100644 (file)
@@ -97,14 +97,21 @@ app_init_eal(struct app_params *app)
        uint32_t i;
        int status;
 
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
+
        app->eal_argv[n_args++] = strdup(app->app_name);
 
        app_core_build_core_mask_string(app, core_mask_str);
        snprintf(buffer, sizeof(buffer), "-c%s", core_mask_str);
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(buffer);
 
        if (p->coremap) {
                snprintf(buffer, sizeof(buffer), "--lcores=%s", p->coremap);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -113,19 +120,27 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--master-lcore=%" PRIu32,
                        p->master_lcore);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        snprintf(buffer, sizeof(buffer), "-n%" PRIu32, p->channels);
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(buffer);
 
        if (p->memory_present) {
                snprintf(buffer, sizeof(buffer), "-m%" PRIu32, p->memory);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->ranks_present) {
                snprintf(buffer, sizeof(buffer), "-r%" PRIu32, p->ranks);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -137,6 +152,8 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--pci-blacklist=%s",
                        p->pci_blacklist[i]);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -149,6 +166,8 @@ app_init_eal(struct app_params *app)
                                sizeof(buffer),
                                "--pci-whitelist=%s",
                                p->pci_whitelist[i]);
+                       if (unlikely (n_args >= APP_EAL_ARGC))
+                               goto error_exit;
                        app->eal_argv[n_args++] = strdup(buffer);
                }
        else
@@ -159,6 +178,8 @@ app_init_eal(struct app_params *app)
                                sizeof(buffer),
                                "--pci-whitelist=%s",
                                pci_bdf);
+                       if (unlikely (n_args >= APP_EAL_ARGC))
+                               goto error_exit;
                        app->eal_argv[n_args++] = strdup(buffer);
                }
 
@@ -170,11 +191,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--vdev=%s",
                        p->vdev[i]);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->vmware_tsc_map_present) && p->vmware_tsc_map) {
                snprintf(buffer, sizeof(buffer), "--vmware-tsc-map");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -183,11 +208,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--proc-type=%s",
                        p->proc_type);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->syslog) {
                snprintf(buffer, sizeof(buffer), "--syslog=%s", p->syslog);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -196,41 +225,57 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--log-level=%" PRIu32,
                        p->log_level);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->version_present) && p->version) {
                snprintf(buffer, sizeof(buffer), "-v");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->help_present) && p->help) {
                snprintf(buffer, sizeof(buffer), "--help");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_huge_present) && p->no_huge) {
                snprintf(buffer, sizeof(buffer), "--no-huge");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_pci_present) && p->no_pci) {
                snprintf(buffer, sizeof(buffer), "--no-pci");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_hpet_present) && p->no_hpet) {
                snprintf(buffer, sizeof(buffer), "--no-hpet");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->no_shconf_present) && p->no_shconf) {
                snprintf(buffer, sizeof(buffer), "--no-shconf");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->add_driver) {
                snprintf(buffer, sizeof(buffer), "-d=%s", p->add_driver);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -239,11 +284,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--socket-mem=%s",
                        p->socket_mem);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if (p->huge_dir) {
                snprintf(buffer, sizeof(buffer), "--huge-dir=%s", p->huge_dir);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -252,6 +301,8 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--file-prefix=%s",
                        p->file_prefix);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -260,11 +311,15 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--base-virtaddr=%s",
                        p->base_virtaddr);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->create_uio_dev_present) && p->create_uio_dev) {
                snprintf(buffer, sizeof(buffer), "--create-uio-dev");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
@@ -273,15 +328,21 @@ app_init_eal(struct app_params *app)
                        sizeof(buffer),
                        "--vfio-intr=%s",
                        p->vfio_intr);
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        if ((p->xen_dom0_present) && (p->xen_dom0)) {
                snprintf(buffer, sizeof(buffer), "--xen-dom0");
+               if (unlikely (n_args >= APP_EAL_ARGC))
+                       goto error_exit;
                app->eal_argv[n_args++] = strdup(buffer);
        }
 
        snprintf(buffer, sizeof(buffer), "--");
+       if (unlikely (n_args >= APP_EAL_ARGC))
+               goto error_exit;
        app->eal_argv[n_args++] = strdup(buffer);
 
        app->eal_argc = n_args;
@@ -297,8 +358,10 @@ app_init_eal(struct app_params *app)
        }
 
        status = rte_eal_init(app->eal_argc, app->eal_argv);
-       if (status < 0)
+       if (status < 0) {
+error_exit:
                rte_panic("EAL init error\n");
+       }
 }
 static inline int
 app_link_filter_arp_add(struct app_link_params *link)
@@ -557,7 +620,7 @@ app_link_up_internal(__rte_unused struct app_params *app,
                struct app_link_params *cp)
 {
        if(app == NULL || cp == NULL)
-               printf("NULL Pointers");
+               rte_panic("NULL Pointers");
 
 #if RTE_VERSION < 0x100b0000
         if (app_link_is_virtual(cp)) {
@@ -576,7 +639,8 @@ app_link_down_internal(__rte_unused struct app_params *app,
                struct app_link_params *cp)
 {
        if(app == NULL || cp == NULL)
-               printf("NULL Pointers");
+               rte_panic("NULL Pointers");
+
 
 #if RTE_VERSION < 0x100b0000
         if (app_link_is_virtual(cp)) {
index f0eab34..71fd5cd 100644 (file)
@@ -1969,7 +1969,7 @@ pipeline_vfw_parse_args(struct pipeline_vfw *vfw_pipe,
               if (strcmp(arg_name, "n_flows") == 0) {
                      int n_flows = atoi(arg_value);
 
-                     if (n_flows == 0)
+                     if ((n_flows == 0) || (n_flows > 8000000))
                             return -1;
 
                      /* must be power of 2, round up if not */