From b7c63d43f23b1478d11396e28f25ad7d809ff0f4 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 6 Apr 2021 13:51:59 +0300 Subject: [PATCH] net: if: Check iface before setting/getting interface MTU Do not try to set or get the interface MTU if the interface pointer is NULL. Coverity-CID: 220541 Fixes #34000 Signed-off-by: Jukka Rissanen --- include/net/net_if.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/net/net_if.h b/include/net/net_if.h index e29d70042e5..dbb3faa703d 100644 --- a/include/net/net_if.h +++ b/include/net/net_if.h @@ -782,6 +782,10 @@ static inline int net_if_set_link_addr(struct net_if *iface, */ static inline uint16_t net_if_get_mtu(struct net_if *iface) { + if (iface == NULL) { + return 0U; + } + return iface->if_dev->mtu; } @@ -794,6 +798,10 @@ static inline uint16_t net_if_get_mtu(struct net_if *iface) static inline void net_if_set_mtu(struct net_if *iface, uint16_t mtu) { + if (iface == NULL) { + return; + } + iface->if_dev->mtu = mtu; }