bridge: fix potential snprintf overflow
Subsystems (2)
PATCH 1/2 bridge: fix potential snprintf overflow
There is a theoretical snprintf overflow in bridge slave bitmask print code found by CodeQL scan.
Signed-off-by Stephen Hemminger <[email protected]>
--- ip/iplink_bridge_slave.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
ip/iplink_bridge_slave.c +9 -2
@@ -100,13 +100,20 @@ static void _bitmask2str(__u16 bitmask, char *dst, size_t dst_size,int len, i;for (i =0 , len =0 ; bitmask; i++, bitmask >>=1 ) { +int n; +if (bitmask &0x1 ) {if (tbl[i]) - len +=snprintf (dst + len, dst_size - len,"%s," , + n =snprintf (dst + len, dst_size - len,"%s," , tbl[i]);else - len +=snprintf (dst + len, dst_size - len,"0x%x," , + n =snprintf (dst + len, dst_size - len,"0x%x," , (1 << i)); + +if (n <0 || n >= dst_size - len) +break ; + + len += n; } }
Signature · 1 line
2.39.2
PATCH 2/2 ila: fix potential snprintf buffer overflow
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 <[email protected]>
--- ip/ipila.c | 2 ++ 1 file changed, 2 insertions(+)
ip/ipila.c +2 -0
@@ -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; } }
Signature · 1 line
2.39.2
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Hello:
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Quoted 7 lines · On Mon, 18 Sep 2023 11:46:30 -0700 you wrote:
There is a theoretical snprintf overflow in bridge slave bitmask print code found by CodeQL scan.
Signed-off-by Stephen Hemminger <[email protected]>--- ip/iplink_bridge_slave.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
Here is the summary with links:
- [iproute2,1/2] bridge: fix potential snprintf overflow
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=4d80122ae82a - [iproute2,2/2] ila: fix potential snprintf buffer overflow https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=e8a3fca81cd4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html