From 1c36ea979faad812c01c0e1cc841beee0f949ceb Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 25 Feb 2022 22:44:23 -0800 Subject: [PATCH] Fix crash on invalid domain --- src/pc/network/socket/domain_res.c | 38 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/pc/network/socket/domain_res.c b/src/pc/network/socket/domain_res.c index fb57c486..264eb08e 100644 --- a/src/pc/network/socket/domain_res.c +++ b/src/pc/network/socket/domain_res.c @@ -12,23 +12,27 @@ void domain_resolution(void) { - struct in_addr addr; - char *host_name; - struct hostent *remoteHost; - char* domainname = ""; - host_name = configJoinIp; - if (host_name == NULL) { - return; - } - int i = 0; - remoteHost = gethostbyname(host_name); - i = 0; - if (remoteHost->h_addrtype == AF_INET) { + struct in_addr addr; + char *host_name = configJoinIp; + struct hostent *remoteHost; + char* domainname = ""; + host_name = configJoinIp; - while (remoteHost->h_addr_list[i] != 0) { - addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++]; - domainname = inet_ntoa(addr); - snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", domainname); + if (host_name == NULL) { + return; + } + + int i = 0; + remoteHost = gethostbyname(host_name); + if (remoteHost == NULL) { + return; + } + + if (remoteHost->h_addrtype == AF_INET) { + while (remoteHost->h_addr_list[i] != 0) { + addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++]; + domainname = inet_ntoa(addr); + snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", domainname); + } } - } }