From 8b9c447063a13f4b2c567e8be378a8c270487003 Mon Sep 17 00:00:00 2001 From: electron128 Date: Sat, 22 Apr 2017 10:13:23 +0200 Subject: [PATCH] fixed possible crash and return value in rsGetHostByName(), thanks to Kotyara for reporting this --- libretroshare/src/util/rsnet.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/util/rsnet.cc b/libretroshare/src/util/rsnet.cc index 63501511b..8b8c9ef82 100644 --- a/libretroshare/src/util/rsnet.cc +++ b/libretroshare/src/util/rsnet.cc @@ -81,15 +81,18 @@ bool rsGetHostByName(const std::string& hostname, in_addr& returned_addr) addrinfo *info = NULL; int res = getaddrinfo(hostname.c_str(),NULL,NULL,&info) ; + bool ok = true; if(res > 0 || info == NULL || info->ai_addr == NULL) { std::cerr << "(EE) getaddrinfo returned error " << res << " on string \"" << hostname << "\"" << std::endl; returned_addr.s_addr = 0 ; + ok = false; } else returned_addr.s_addr = ((sockaddr_in*)info->ai_addr)->sin_addr.s_addr ; - freeaddrinfo(info) ; + if(info) + freeaddrinfo(info) ; #ifdef DEPRECATED_TO_REMOVE #if defined(WINDOWS_SYS) || defined(__APPLE__) || defined(__HAIKU__) @@ -123,7 +126,7 @@ bool rsGetHostByName(const std::string& hostname, in_addr& returned_addr) returned_addr.s_addr = *(unsigned long*) (result->h_addr); #endif - return true ; + return ok; } bool isValidNet(const struct in_addr *addr)