Skip to contentSkip to conversation

ip: ipmaddr.c: Fix possible integer underflow in read_igmp()

PATCH Superseded Anton Moryakov 2 participants 2 messages Jul 19, 2025 – Jul 20, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip: ipmaddr.c: Fix possible integer underflow in read_igmp()

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
---
 ip/ipmaddr.c | 2 ++
 1 file changed, 2 insertions(+)
ip/ipmaddr.c +2 -0
index 2418b303..2feb916a 100644
@@ -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;
Signature · 1 line
2.39.2
#1 lore raw
Quoted 20 lines · On Sat, 19 Jul 2025 18:57:05 +0300 Anton Moryakov <[email protected]>…

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
---
 ip/ipmaddr.c | 2 ++
 1 file changed, 2 insertions(+)
ip/ipmaddr.c +0 -0
index 2418b303..2feb916a 100644

ip/ipmaddr.c static void read_igmp(struct ma_info **result_p) · line 154

Quoted 5 lines
ip/ipmaddr.c +2 -0
@@ -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)