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 <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2021-04-06 13:51:59 +03:00 committed by Anas Nashif
commit b7c63d43f2

View file

@ -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) static inline uint16_t net_if_get_mtu(struct net_if *iface)
{ {
if (iface == NULL) {
return 0U;
}
return iface->if_dev->mtu; 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, static inline void net_if_set_mtu(struct net_if *iface,
uint16_t mtu) uint16_t mtu)
{ {
if (iface == NULL) {
return;
}
iface->if_dev->mtu = mtu; iface->if_dev->mtu = mtu;
} }