From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 18D95A04AF; Fri, 21 Aug 2020 19:11:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 375CD1C0CE; Fri, 21 Aug 2020 19:10:58 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id CB8F61C0CD; Fri, 21 Aug 2020 19:10:56 +0200 (CEST) IronPort-SDR: XkmuyUoqMKUUgBv+b/cBNSg3UE4OCUiCdliojhOBN87MUYthbzr8974cIQilrleypy+ddhM0nN Ty6JvReJVU+g== X-IronPort-AV: E=McAfee;i="6000,8403,9720"; a="152998910" X-IronPort-AV: E=Sophos;i="5.76,338,1592895600"; d="scan'208";a="152998910" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2020 10:10:56 -0700 IronPort-SDR: QkLvB0bTlWpifxQJwuP4NYviknOSP1GxMmbiviQi/JTQ/+RHAF9LptcD6FyiHZCZqyuGxpEjrQ oZgxcKlGZM9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,338,1592895600"; d="scan'208";a="498037806" Received: from silpixa00399126.ir.intel.com ([10.237.222.56]) by fmsmga006.fm.intel.com with ESMTP; 21 Aug 2020 10:10:55 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , stable@dpdk.org, Stephen Hemminger , Anatoly Burakov Date: Fri, 21 Aug 2020 18:10:16 +0100 Message-Id: <20200821171017.50531-4-bruce.richardson@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200821171017.50531-1-bruce.richardson@intel.com> References: <20200814110045.217724-1-bruce.richardson@intel.com> <20200821171017.50531-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 3/4] examples/mp_server: fix snprintf overflow 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When producing a printable mac address the buffer was appropriately sized for holding the mac address exactly, but the actual snprintf included a '\n' character at the end, which means that the snprintf technically is getting truncated i.e. the \n would not be added due to lack of space. This gets flagged as a problem by modern versions of gcc, e.g. on Ubuntu 20.04. main.c:77:37: warning: ‘__builtin___snprintf_chk’ output truncated before the last format character [-Wformat-truncation=] 77 | "%02x:%02x:%02x:%02x:%02x:%02x\n", | ^ Since the \n is getting stripped anyway, we can fix the issue by just removing it. In the process we can switch to using the standard ethernet address formating function from rte_ether.h. Fixes: af75078fece3 ("first public release") Cc: stable@dpdk.org Cc: Stephen Hemminger Signed-off-by: Bruce Richardson --- V2: switched code to use standard formatting function --- .../client_server_mp/mp_server/main.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/multi_process/client_server_mp/mp_server/main.c b/examples/multi_process/client_server_mp/mp_server/main.c index 280dab8672..fb2aa49678 100644 --- a/examples/multi_process/client_server_mp/mp_server/main.c +++ b/examples/multi_process/client_server_mp/mp_server/main.c @@ -59,12 +59,17 @@ static struct client_rx_buf *cl_rx_buf; static const char * get_printable_mac_addr(uint16_t port) { - static const char err_address[] = "00:00:00:00:00:00"; - static char addresses[RTE_MAX_ETHPORTS][sizeof(err_address)]; + static const struct rte_ether_addr null_mac; /* static defaults to 0 */ + static char err_address[32]; + static char addresses[RTE_MAX_ETHPORTS][32]; int ret; - if (unlikely(port >= RTE_MAX_ETHPORTS)) + if (unlikely(port >= RTE_MAX_ETHPORTS)) { + if (err_address[0] == '\0') + rte_ether_format_addr(err_address, + sizeof(err_address), &null_mac); return err_address; + } if (unlikely(addresses[port][0]=='\0')){ struct rte_ether_addr mac; ret = rte_eth_macaddr_get(port, &mac); @@ -73,10 +78,8 @@ get_printable_mac_addr(uint16_t port) port, rte_strerror(-ret)); return err_address; } - snprintf(addresses[port], sizeof(addresses[port]), - "%02x:%02x:%02x:%02x:%02x:%02x\n", - mac.addr_bytes[0], mac.addr_bytes[1], mac.addr_bytes[2], - mac.addr_bytes[3], mac.addr_bytes[4], mac.addr_bytes[5]); + rte_ether_format_addr(addresses[port], + sizeof(addresses[port]), &mac); } return addresses[port]; } -- 2.25.1