diff mbox series

[iproute2,2/2] ila: fix potential snprintf buffer overflow

Message ID 20230918184631.16228-2-stephen@networkplumber.org (mailing list archive)
State Accepted
Commit e8a3fca81cd4b8fee14cfb14a5ce9c1b3b63e797
Delegated to: Stephen Hemminger
Headers show
Series [iproute2,1/2] bridge: fix potential snprintf overflow | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger Sept. 18, 2023, 6:46 p.m. UTC
The code to print 64 bit address has a theoretical overflow
of snprintf buffer found by CodeQL scan.
Address by checking result.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 ip/ipila.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/ip/ipila.c b/ip/ipila.c
index 4f6d578f24ae..23b19a108862 100644
--- a/ip/ipila.c
+++ b/ip/ipila.c
@@ -60,6 +60,8 @@  static void print_addr64(__u64 addr, char *buff, size_t len)
 			sep = "";
 
 		ret = snprintf(&buff[written], len - written, "%x%s", v, sep);
+		if (ret < 0 || ret >= len - written)
+			break;
 		written += ret;
 	}
 }