From 484b930fd1bb3d32871cd91f6a2bf5c459081e66 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Sat, 19 Mar 2022 00:57:37 +0800 Subject: [PATCH] netdb/getaddrinfo: fix NULL pointer reference Signed-off-by: chao.an --- libs/libc/netdb/lib_getaddrinfo.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libs/libc/netdb/lib_getaddrinfo.c b/libs/libc/netdb/lib_getaddrinfo.c index bb14ef3967..cc6b9f0571 100644 --- a/libs/libc/netdb/lib_getaddrinfo.c +++ b/libs/libc/netdb/lib_getaddrinfo.c @@ -290,11 +290,10 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname, if (ai != NULL) { *res = (FAR struct addrinfo *)ai; - } - - if (flags & AI_CANONNAME) - { - ai->ai.ai_canonname = (FAR char *)hostname; + if (flags & AI_CANONNAME) + { + ai->ai.ai_canonname = (FAR char *)hostname; + } } return (*res != NULL) ? OK : EAI_MEMORY;