net: ip: guard multicast APIs against NULL args#107851
net: ip: guard multicast APIs against NULL args#107851walidbadar wants to merge 2 commits intozephyrproject-rtos:mainfrom
Conversation
Add NULL checks for iface and addr in IPv4/IPv6 maddr add/rm to prevent potential dereferences. Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
There was a problem hiding this comment.
The documentation states that NULL can be returned:
zephyr/include/zephyr/net/net_if.h
Lines 1488 to 1493 in 33d8974
It is up to the caller to validate, no?
diff --git a/samples/net/telnet/src/telnet.c b/samples/net/telnet/src/telnet.c
index 1673485f14b..5f6b22c2f75 100644
--- a/samples/net/telnet/src/telnet.c
+++ b/samples/net/telnet/src/telnet.c
@@ -26,6 +26,11 @@ static void setup_ipv6(void)
struct net_in6_addr addr;
struct net_if *iface = net_if_get_default();
+ if (iface == NULL) {
+ LOG_ERR("No default interface");
+ return;
+ }
+
if (net_addr_pton(NET_AF_INET6, MCAST_IP6ADDR, &addr)) {
LOG_ERR("Invalid address: %s", MCAST_IP6ADDR);
return;
True, the sample could/should check the interface, but still those NULL checks are fine additions IMO. |
Avoid null pointer dereference by validating net_if_get_default(). Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
|
I get that this is defensive programming, and I'm not blocking in any way. But this is only a fraction of the entire code-base where this is now "fixed". IMO, the The problem is mostly in the documentation/contract, we should make it clear where it is allowed or not allowed to pass |
But in case of caller forgets to validate that NULL pointer and it is passed down, then It is also the responsibility of that API to validate. |
Depends, if the API states that |
|



Add NULL checks for iface and addr in IPv4/IPv6 maddr add/rm to prevent potential dereferences.