]> git.droids-corp.org - dpdk.git/commitdiff
app/testpmd: fix stack overflow for EEPROM display
authorSteve Yang <stevex.yang@intel.com>
Thu, 20 Jan 2022 02:59:31 +0000 (02:59 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Thu, 3 Feb 2022 13:13:32 +0000 (14:13 +0100)
When the size of EEPROM exceeds the default thread stack size(8MB),
e.g.: 10MB size, it will crash due to stack overflow.

Allocate the data of EPPROM information on the heap.

Fixes: 6b67721dee2a ("app/testpmd: add EEPROM command")
Cc: stable@dpdk.org
Signed-off-by: Steve Yang <stevex.yang@intel.com>
Acked-by: Aman Singh <aman.deep.singh@intel.com>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
app/test-pmd/config.c

index 1722d6c8f88ca95e046e0147d7c4f62dbede1c8d..e812f5715139d3c87f34e4a90fab55856e6df285 100644 (file)
@@ -912,10 +912,15 @@ port_eeprom_display(portid_t port_id)
                return;
        }
 
-       char buf[len_eeprom];
        einfo.offset = 0;
        einfo.length = len_eeprom;
-       einfo.data = buf;
+       einfo.data = calloc(1, len_eeprom);
+       if (!einfo.data) {
+               fprintf(stderr,
+                       "Allocation of port %u eeprom data failed\n",
+                       port_id);
+               return;
+       }
 
        ret = rte_eth_dev_get_eeprom(port_id, &einfo);
        if (ret != 0) {
@@ -933,10 +938,12 @@ port_eeprom_display(portid_t port_id)
                        fprintf(stderr, "Unable to get EEPROM: %d\n", ret);
                        break;
                }
+               free(einfo.data);
                return;
        }
        rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
        printf("Finish -- Port: %d EEPROM length: %d bytes\n", port_id, len_eeprom);
+       free(einfo.data);
 }
 
 void
@@ -972,10 +979,15 @@ port_module_eeprom_display(portid_t port_id)
                return;
        }
 
-       char buf[minfo.eeprom_len];
        einfo.offset = 0;
        einfo.length = minfo.eeprom_len;
-       einfo.data = buf;
+       einfo.data = calloc(1, minfo.eeprom_len);
+       if (!einfo.data) {
+               fprintf(stderr,
+                       "Allocation of port %u eeprom data failed\n",
+                       port_id);
+               return;
+       }
 
        ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
        if (ret != 0) {
@@ -994,11 +1006,13 @@ port_module_eeprom_display(portid_t port_id)
                                ret);
                        break;
                }
+               free(einfo.data);
                return;
        }
 
        rte_hexdump(stdout, "hexdump", einfo.data, einfo.length);
        printf("Finish -- Port: %d MODULE EEPROM length: %d bytes\n", port_id, einfo.length);
+       free(einfo.data);
 }
 
 int