public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ipmaddr: Add check for result of sscanf
@ 2024-02-18 20:42 Maks Mishin
  2024-02-19 17:31 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Maks Mishin @ 2024-02-18 20:42 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Maks Mishin, netdev

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

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 ip/ipmaddr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
index 2418b303..00e91004 100644
--- a/ip/ipmaddr.c
+++ b/ip/ipmaddr.c
@@ -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';
-- 
2.30.2


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

* Re: [PATCH] ipmaddr: Add check for result of sscanf
  2024-02-18 20:42 [PATCH] ipmaddr: Add check for result of sscanf Maks Mishin
@ 2024-02-19 17:31 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2024-02-19 17:31 UTC (permalink / raw)
  To: Maks Mishin; +Cc: netdev

On Sun, 18 Feb 2024 23:42:03 +0300
Maks Mishin <maks.mishinfz@gmail.com> 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 <maks.mishinFZ@gmail.com>
> ---
>  ip/ipmaddr.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
> index 2418b303..00e91004 100644
> --- a/ip/ipmaddr.c
> +++ b/ip/ipmaddr.c
> @@ -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.

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

end of thread, other threads:[~2024-02-19 17:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-18 20:42 [PATCH] ipmaddr: Add check for result of sscanf Maks Mishin
2024-02-19 17:31 ` Stephen Hemminger

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