From 4e7f3236330f02a08fcac3d73b66a8d0c20bc2c6 Mon Sep 17 00:00:00 2001 From: meijian Date: Thu, 24 Oct 2024 11:13:14 +0800 Subject: [PATCH] net/getifaddrs: fix coverity bug Signed-off-by: meijian --- libs/libc/net/lib_getifaddrs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/libc/net/lib_getifaddrs.c b/libs/libc/net/lib_getifaddrs.c index 2bb67dc806..4526b280b4 100644 --- a/libs/libc/net/lib_getifaddrs.c +++ b/libs/libc/net/lib_getifaddrs.c @@ -83,6 +83,11 @@ static FAR struct myifaddrs *getmutil_ipv6addr(int fd, struct lifreq *req, FAR struct sockaddr_in6 *ipv6addr; int index; + if (req == NULL || ifaddr == NULL) + { + return NULL; + } + /* eth0:0 is the second ipaddr */ for (index = 0; index < CONFIG_NETDEV_MAX_IPv6_ADDR - 1; index++) @@ -108,7 +113,7 @@ static FAR struct myifaddrs *getmutil_ipv6addr(int fd, struct lifreq *req, } ifaddr->addrs.ifa_next = lib_zalloc(sizeof(*ifaddr)); - if (ifaddr == NULL) + if (ifaddr->addrs.ifa_next == NULL) { return NULL; }