mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 23:28:29 +08:00
libc/netdb: Move hostbuffer out of the stack
The length of hostbuffer come from Kconfig, it isn't safe to allocate this variable on the stack. Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I75213688153a1cba738544de2a51fa3247626dd3
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
0fbfc4c44c
commit
922cf0612b
@@ -124,7 +124,7 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
|
||||
int flags = 0;
|
||||
int proto = 0;
|
||||
int socktype = 0;
|
||||
char hostbuffer[CONFIG_NETDB_BUFSIZE];
|
||||
FAR char *hostbuffer;
|
||||
FAR struct hostent_s host;
|
||||
FAR struct ai_s *ai;
|
||||
FAR struct ai_s *prev_ai = NULL;
|
||||
@@ -280,12 +280,19 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
|
||||
#endif /* CONFIG_NET_LOOPBACK */
|
||||
}
|
||||
|
||||
hostbuffer = lib_malloc(CONFIG_NETDB_BUFSIZE);
|
||||
if (hostbuffer == NULL)
|
||||
{
|
||||
return EAI_MEMORY;
|
||||
}
|
||||
|
||||
/* REVISIT: no check for AI_NUMERICHOST flag. */
|
||||
|
||||
gethostentbyname_r(hostname, &host,
|
||||
hostbuffer, sizeof(hostbuffer), &ret);
|
||||
hostbuffer, CONFIG_NETDB_BUFSIZE, &ret);
|
||||
if (ret != OK)
|
||||
{
|
||||
lib_free(hostbuffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -309,6 +316,7 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
|
||||
freeaddrinfo(*res);
|
||||
}
|
||||
|
||||
lib_free(hostbuffer);
|
||||
return EAI_MEMORY;
|
||||
}
|
||||
|
||||
@@ -337,5 +345,6 @@ int getaddrinfo(FAR const char *hostname, FAR const char *servname,
|
||||
prev_ai = ai;
|
||||
}
|
||||
|
||||
lib_free(hostbuffer);
|
||||
return (*res != NULL) ? OK : EAI_FAMILY;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user