Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2-next] ip: ipmaddr.c: Fix possible integer underflow in read_igmp()
@ 2025-07-19 15:57 Anton Moryakov
  2025-07-20 15:13 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Anton Moryakov @ 2025-07-19 15:57 UTC (permalink / raw)
  To: netdev; +Cc: Anton Moryakov

Static analyzer pointed out a potential error:

	Possible integer underflow: left operand is tainted. An integer underflow 
	may occur due to arithmetic operation (unsigned subtraction) between variable 
	'len' and value '1', when 'len' is tainted { [0, 18446744073709551615] }

The fix adds a check for 'len == 0' before accessing the last character of
the name, and skips the current line in such cases to avoid the underflow.

Reported-by: SVACE static analyzer
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
 ip/ipmaddr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
index 2418b303..2feb916a 100644
--- a/ip/ipmaddr.c
+++ b/ip/ipmaddr.c
@@ -150,6 +150,8 @@ static void read_igmp(struct ma_info **result_p)
 
 			sscanf(buf, "%d%s", &m.index, m.name);
 			len = strlen(m.name);
+			if(len == 0)
+				continue;
 			if (m.name[len - 1] == ':')
 				m.name[len - 1] = '\0';
 			continue;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2-next] ip: ipmaddr.c: Fix possible integer underflow in read_igmp()
  2025-07-19 15:57 [PATCH iproute2-next] ip: ipmaddr.c: Fix possible integer underflow in read_igmp() Anton Moryakov
@ 2025-07-20 15:13 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2025-07-20 15:13 UTC (permalink / raw)
  To: Anton Moryakov; +Cc: netdev

On Sat, 19 Jul 2025 18:57:05 +0300
Anton Moryakov <ant.v.moryakov@gmail.com> wrote:

> Static analyzer pointed out a potential error:
> 
> 	Possible integer underflow: left operand is tainted. An integer underflow 
> 	may occur due to arithmetic operation (unsigned subtraction) between variable 
> 	'len' and value '1', when 'len' is tainted { [0, 18446744073709551615] }
> 
> The fix adds a check for 'len == 0' before accessing the last character of
> the name, and skips the current line in such cases to avoid the underflow.
> 
> Reported-by: SVACE static analyzer
> Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
> ---
>  ip/ipmaddr.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
> index 2418b303..2feb916a 100644
> --- a/ip/ipmaddr.c
> +++ b/ip/ipmaddr.c
> @@ -150,6 +150,8 @@ static void read_igmp(struct ma_info **result_p)
>  
>  			sscanf(buf, "%d%s", &m.index, m.name);
>  			len = strlen(m.name);
> +			if(len == 0)
> +				continue;

Need to follow kernel coding style, need space here.
	if (len == 0)
not
	if(len == 0)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-20 15:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-19 15:57 [PATCH iproute2-next] ip: ipmaddr.c: Fix possible integer underflow in read_igmp() Anton Moryakov
2025-07-20 15:13 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox