|WARNING| [v4] ethdev: add buffer size parameter to rte_eth_dev_get_name_by_port()

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Wed Aug 5 19:34:22 CEST 2026


Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/167207

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-08-05

# DPDK Patch Review

## Summary
This patch adds a size parameter to `rte_eth_dev_get_name_by_port()` to prevent buffer overflows by replacing `strcpy()` with `strlcpy()`. The implementation is correct and all in-tree callers have been updated appropriately.

## Errors

None.

## Warnings

**lib/pdump/rte_pdump.c (line 739)**

Buffer size passed to `rte_eth_dev_get_name_by_port()` is incorrect.

The function `pdump_validate_port()` declares a parameter `char *name` with no known size, but passes `sizeof(name)` as the buffer size. `sizeof(name)` evaluates to the size of the pointer (typically 8 bytes on 64-bit), not the buffer size.

Suggested fix:
```c
/* Change the function signature to accept a size parameter */
static int
pdump_validate_port(uint16_t port, char *name, size_t size)
{
    /* ... */
    ret = rte_eth_dev_get_name_by_port(port, name, size);
    /* ... */
}

/* Or, if name is known to be RTE_ETH_NAME_MAX_LEN, use that constant: */
ret = rte_eth_dev_get_name_by_port(port, name, RTE_ETH_NAME_MAX_LEN);
```

Without seeing the full context of `pdump_validate_port()`'s callers, the safest fix is to require the caller to pass the size, or to document that `name` must be at least `RTE_ETH_NAME_MAX_LEN` bytes and use that constant.

---

**lib/ethdev/rte_ethdev.c (line 736)**

The error message for a zero-size buffer is logged even though the following validation would reject it. This is acceptable but could be consolidated.

Suggested simplification (optional):
```c
if (name == NULL || size == 0) {
    RTE_ETHDEV_LOG_LINE(ERR,
        "Cannot get ethdev port %u name: invalid name buffer",
        port_id);
    return -EINVAL;
}
```

This reduces code duplication and provides a single error path for invalid buffer parameters.

---

## Info

**app/pdump/main.c and app/test/ files**

Several callers now check the return value of `rte_eth_dev_get_name_by_port()` before proceeding (e.g., lines 542, 550, 195, 160). This is good defensive programming. The original code would have proceeded with an uninitialized or garbage `name` buffer on error.

**lib/ethdev/rte_ethdev.c (line 741)**

The comment about VDEV PMD overwriting the per-process data pointer is helpful context for why the shared data is used instead of `rte_eth_devices[].data->name`.

**Release notes**

The API change is correctly documented in `doc/guides/rel_notes/release_26_11.rst`. This is a breaking API change that adds a mandatory parameter.


More information about the test-report mailing list