net: if: Fix if_ipv4_get_addr() locking

net_if_lock() should be called only after iface pointer is verified not
to be NULL, otherwise we can end up dereferencing NULL pointer in
certain corner cases.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2023-07-13 13:33:16 +02:00 committed by Carles Cufí
parent 440af3ecc8
commit cc81dca556

View file

@ -3285,12 +3285,12 @@ static struct in_addr *if_ipv4_get_addr(struct net_if *iface,
struct net_if_ipv4 *ipv4;
int i;
net_if_lock(iface);
if (!iface) {
goto out;
return NULL;
}
net_if_lock(iface);
ipv4 = iface->config.ip.ipv4;
if (!ipv4) {
goto out;