ipmaddr: Add check for result of sscanf
Subsystems (2)
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.
Signed-off-by Maks Mishin <[email protected]>
--- ip/ipmaddr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
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 ; + len =strlen (m.name);if (m.name[len -1 ] ==':' ) m.name[len -1 ] ='\0' ;
Signature · 1 line
2.30.2
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.Signed-off-by Maks Mishin <[email protected]>--- ip/ipmaddr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)ip/ipmaddr.c +0
-0
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.