From: Stephen Hemminger Date: Thu, 28 Feb 2019 22:47:53 +0000 (-0800) Subject: ethdev: replace snprintf with strlcpy for owner X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e97f83e452b8b2498c3c6ce2ff0cf94b65a62306;hp=d9263ab13886f8b25a324e40ddb205f1a3f71c6d;p=dpdk.git ethdev: replace snprintf with strlcpy for owner The set_port_owner was copying a string between structures of the same type, therefore the name could never be truncated (unless source string was not null terminated). Use strlcpy which does it better. Signed-off-by: Stephen Hemminger Acked-by: Andrew Rybchenko --- diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 85c1794968..95889ed206 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -585,7 +585,6 @@ _rte_eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id, { struct rte_eth_dev *ethdev = &rte_eth_devices[port_id]; struct rte_eth_dev_owner *port_owner; - int sret; if (port_id >= RTE_MAX_ETHPORTS || !is_allocated(ethdev)) { RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n", @@ -609,11 +608,8 @@ _rte_eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id, return -EPERM; } - sret = snprintf(port_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN, "%s", - new_owner->name); - if (sret < 0 || sret >= RTE_ETH_MAX_OWNER_NAME_LEN) - RTE_ETHDEV_LOG(ERR, "Port %u owner name was truncated\n", - port_id); + /* can not truncate (same structure) */ + strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN); port_owner->id = new_owner->id;