From 971ae599130dff34cfe530121015d34aa1720729 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 29 Oct 2019 12:25:30 +0200 Subject: [PATCH] net: pkt: Make sure iface is not null when accessing L2 It is possible that the network interface is not set when we check the interface in net_pkt.c:pkt_buffer_length(). For example in icmpv6 unit test the interface is left as NULL as the test does not care about what network interface is used. For real hw like mimxrt1050_evk, which supports Ethernet, we need to add additional checks for the interface being non-null. Fixes #20088 Signed-off-by: Jukka Rissanen --- include/net/net_if.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/net/net_if.h b/include/net/net_if.h index 906b7202e5d..413f7bd8f54 100644 --- a/include/net/net_if.h +++ b/include/net/net_if.h @@ -550,6 +550,10 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt); */ static inline const struct net_l2 * const net_if_l2(struct net_if *iface) { + if (!iface) { + return NULL; + } + return iface->if_dev->l2; }