[dpdk-stable] [PATCH 3/4] examples/mp_server: fix snprintf overflow

Bruce Richardson bruce.richardson at intel.com
Fri Aug 14 13:00:44 CEST 2020


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 from the printf string.

Fixes: af75078fece3 ("first public release")
Cc: stable at dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
 examples/multi_process/client_server_mp/mp_server/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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..af5af672c3 100644
--- a/examples/multi_process/client_server_mp/mp_server/main.c
+++ b/examples/multi_process/client_server_mp/mp_server/main.c
@@ -74,7 +74,7 @@ get_printable_mac_addr(uint16_t port)
 			return err_address;
 		}
 		snprintf(addresses[port], sizeof(addresses[port]),
-				"%02x:%02x:%02x:%02x:%02x:%02x\n",
+				"%02x:%02x:%02x:%02x:%02x:%02x",
 				mac.addr_bytes[0], mac.addr_bytes[1], mac.addr_bytes[2],
 				mac.addr_bytes[3], mac.addr_bytes[4], mac.addr_bytes[5]);
 	}
-- 
2.25.1



More information about the stable mailing list