Skip to contentSkip to conversation

ipmaddr: Add check for result of sscanf

PATCH In review Maks Mishin 2 participants 2 messages Feb 18, 2024 – Feb 19, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipmaddr: Add check for result of sscanf

Added comparison of result sscanf with 2 to avoid
potential troubles with args of sscanf.
Found by RASU JSC.

---
 ip/ipmaddr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ip/ipmaddr.c +3 -1
index 2418b303..00e91004 100644
@@ -148,7 +148,9 @@ static void read_igmp(struct ma_info **result_p)
 		if (buf[0] != '\t') {
 			size_t len;
 
-			sscanf(buf, "%d%s", &m.index, m.name);
+			if (sscanf(buf, "%d%s", &m.index, m.name) != 2)
+				return;
+
 			len = strlen(m.name);
 			if (m.name[len - 1] == ':')
 				m.name[len - 1] = '\0';
Signature · 1 line
2.30.2
#1 lore raw
Quoted 14 lines · On Sun, 18 Feb 2024 23:42:03 +0300 Maks Mishin <[email protected]> wrote:

Added comparison of result sscanf with 2 to avoid
potential troubles with args of sscanf.
Found by RASU JSC.

---
 ip/ipmaddr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ip/ipmaddr.c +0 -0
index 2418b303..00e91004 100644

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

Quoted 7 lines
ip/ipmaddr.c +3 -1
@@ -148,7 +148,9 @@ static void read_igmp(struct ma_info **result_p)
 		if (buf[0] != '\t') {
 			size_t len;
 
-			sscanf(buf, "%d%s", &m.index, m.name);
+			if (sscanf(buf, "%d%s", &m.index, m.name) != 2)
+				return;
+

You didn't look at surrounding code.
That will leak the file descriptor.
Please review you patches more carefully.

This is reading from kernel /proc/net/igmp. And the ABI for that is stable so not a serious concern. It would be good if this was available over better API like netlink, but few users get into the weed of multicast.