Project

General

Profile

Actions

Bug #8273

open

dpdk: adjust variable sizes in xstats printing

Added by Lukas Sismis 6 days ago. Updated 5 days ago.

Status:
New
Priority:
Normal
Assignee:
Target version:
Affected Versions:
Effort:
Difficulty:
Label:

Description

Address copilot comments from https://github.com/OISF/suricata/pull/14771

src/source-dpdk.c
Comment on lines +493 to +496
uint16_t len = (uint16_t)ret;

xstats = SCCalloc(len, sizeof(*xstats));
if (xstats == NULL) {
Copilot AI
yesterday
len is stored as uint16_t, but rte_eth_xstats_get(..., NULL, 0) returns an int count and the API takes an unsigned int n. If the xstat count exceeds 65535, this will truncate len, leading to under-allocation and subsequent ret > len paths. Use an unsigned int/uint32_t for len (and the allocation size) to match the DPDK API and avoid truncation.

src/source-dpdk.c
Comment on lines +488 to +499
int32_t ret = rte_eth_xstats_get(port_id, NULL, 0);
if (ret < 0) {
SCLogPerf("%s: unable to obtain rte_eth_xstats (%s)", port_name, rte_strerror(-ret));
return;
}
uint16_t len = (uint16_t)ret;

xstats = SCCalloc(len, sizeof(*xstats));
if (xstats NULL) {
SCLogWarning("Failed to allocate memory for the rte_eth_xstat structure");
return;
}
Copilot AI
yesterday
If rte_eth_xstats_get(port_id, NULL, 0) returns 0 (no xstats), SCCalloc(len, ...) will be called with len 0, which may return NULL and triggers a misleading "Failed to allocate" warning. Consider handling len == 0 as a valid case and return early without logging a warning.

src/source-dpdk.c
Comment on lines +501 to +505
ret = rte_eth_xstats_get(port_id, xstats, len);
if (ret < 0 || ret > len) {
SCFree(xstats);
SCLogPerf("%s: unable to obtain rte_eth_xstats (%s)", port_name, rte_strerror(-ret));
return;
Copilot AI
yesterday
In the ret < 0 || ret > len branch, the log uses rte_strerror(-ret). When ret > len, ret is positive (not an errno), so passing -ret to rte_strerror is incorrect/misleading. Split the cases: use rte_strerror(-ret) only for ret < 0, and for ret > len log an "unexpected xstats count" style message (and consider re-querying the required size).


Subtasks 2 (2 open0 closed)

Bug #8274: dpdk: adjust variable sizes in xstats printing (8.0.x backport)AssignedLukas SismisActions
Bug #8275: dpdk: adjust variable sizes in xstats printing (7.0.x backport)AssignedLukas SismisActions
Actions #1

Updated by Lukas Sismis 5 days ago

  • Target version changed from TBD to 9.0.0-beta1
Actions #2

Updated by OISF Ticketbot 5 days ago

  • Subtask #8274 added
Actions #3

Updated by OISF Ticketbot 5 days ago

  • Label deleted (Needs backport to 8.0)
Actions #4

Updated by OISF Ticketbot 5 days ago

  • Subtask #8275 added
Actions #5

Updated by OISF Ticketbot 5 days ago

  • Label deleted (Needs backport to 7.0)
Actions

Also available in: Atom PDF