From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by dpdk.org (Postfix) with ESMTP id 6E2CA37A2 for ; Thu, 28 Feb 2019 23:48:00 +0100 (CET) Received: by mail-pg1-f196.google.com with SMTP id u9so10417631pgo.7 for ; Thu, 28 Feb 2019 14:48:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q0mduZvXkrFQCroWkgq//tW95KUAvdvTap2FtPQLIQY=; b=qb3qr0K6BMZ9mWrk+bT3Cvc+RS8rascR1hc1g4hlnpVs1l8qabSPjwaRJIW45umI6z EzzDzIuPsH0rWw2Xqx+/PMAB4rkq7oBJjNY73jeJmZXchkB7aB4eeuCSloomsyezac4w 1xN3kyWm9ofUF6/0vL4f6pZ6e4OHhKSH45gAkHnKcYVT/Wa3CjavExjid0as6I/cnjST uadzupf5AzCI8/COqPBo1vzyFRCwR1kyjqap57xA+moso+puCw6zQocqN/TSA9DCQT/4 I1rhBoAVdHH8Mh0DvEV4IMUbsFF1T13q3qqegmMGZEK2Dh+71epLtUh9EnIvZy5vAeOO 2s0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q0mduZvXkrFQCroWkgq//tW95KUAvdvTap2FtPQLIQY=; b=Jv+tnEhnJ37d3Xfa1NFlfFn9Ir0LarLHpOVH1g5s7aeCxYaQ9mW0YV5dBXh4rr0Pds cBuLJmyFeWVXs8MWHjaVnrMwPQIC2Ur7t/+COhcVhXBUy3aEvweH439OzzH2vPsc6EM5 6GDTKmoyXyB/5+5OcPqyCYyQLRDS4138Y1EgLLNKoCvyny6Xst8iRK0XH7y22ND1/9JW BBW9pY3cRqqtiJdHvmjw06VuovneWpjD/JtYE56vfvQbEQ647haCPhvbx6kcrnd3+Qyz 26g5UbJfH3iMJ4klO8Blap6sTCRfkctHdhiXx3aOFSZPTxAPCyV9SonU8Dzln6z0/34h hCow== X-Gm-Message-State: APjAAAUyPWFTfMh95Z19v6LTkbCBpVD0sRhdnUZyeZEqTBeyaCAXx7/V hlpP7Px/8V1c8UFuqt2HIgmUYHFuTMw= X-Google-Smtp-Source: APXvYqz/8f6ZKnHNaxJC/J1NJlXyh4g+suMkWWE9l8Uk4j5KLjZ0uvZwPRefivgnnv/YO26F5PWyoA== X-Received: by 2002:a65:5788:: with SMTP id b8mr1562685pgr.8.1551394078827; Thu, 28 Feb 2019 14:47:58 -0800 (PST) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id r28sm48550833pgl.72.2019.02.28.14.47.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 14:47:57 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 28 Feb 2019 14:47:53 -0800 Message-Id: <20190228224754.26511-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190228224754.26511-1-stephen@networkplumber.org> References: <20190228224754.26511-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 1/2] ethdev: replace snprintf with strlcpy X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2019 22:48:00 -0000 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 --- lib/librte_ethdev/rte_ethdev.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 85c1794968dd..95889ed206db 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; -- 2.17.1