Browse Source

Merge pull request #188 from paullouisageneau/fix-freeaddrinfo

Fix freeaddrinfo() called with NULL on getaddrinfo() failure
Paul-Louis Ageneau 4 years ago
parent
commit
9e38d08c0b
2 changed files with 12 additions and 5 deletions
  1. 4 3
      src/candidate.cpp
  2. 8 2
      src/icetransport.cpp

+ 4 - 3
src/candidate.cpp

@@ -94,7 +94,7 @@ bool Candidate::resolve(ResolveMode mode) {
 
 
 		struct addrinfo *result = nullptr;
 		struct addrinfo *result = nullptr;
 		if (getaddrinfo(node.c_str(), service.c_str(), &hints, &result) == 0) {
 		if (getaddrinfo(node.c_str(), service.c_str(), &hints, &result) == 0) {
-			for (auto p = result; p; p = p->ai_next)
+			for (auto p = result; p; p = p->ai_next) {
 				if (p->ai_family == AF_INET || p->ai_family == AF_INET6) {
 				if (p->ai_family == AF_INET || p->ai_family == AF_INET6) {
 					// Rewrite the candidate
 					// Rewrite the candidate
 					char nodebuffer[MAX_NUMERICNODE_LEN];
 					char nodebuffer[MAX_NUMERICNODE_LEN];
@@ -113,9 +113,10 @@ bool Candidate::resolve(ResolveMode mode) {
 						break;
 						break;
 					}
 					}
 				}
 				}
-		}
+			}
 
 
-		freeaddrinfo(result);
+			freeaddrinfo(result);
+		}
 	}
 	}
 
 
 	return mIsResolved;
 	return mIsResolved;

+ 8 - 2
src/icetransport.cpp

@@ -380,8 +380,11 @@ IceTransport::IceTransport(const Configuration &config, Description::Role role,
 		hints.ai_protocol = IPPROTO_UDP;
 		hints.ai_protocol = IPPROTO_UDP;
 		hints.ai_flags = AI_ADDRCONFIG;
 		hints.ai_flags = AI_ADDRCONFIG;
 		struct addrinfo *result = nullptr;
 		struct addrinfo *result = nullptr;
-		if (getaddrinfo(server.hostname.c_str(), server.service.c_str(), &hints, &result) != 0)
+		if (getaddrinfo(server.hostname.c_str(), server.service.c_str(), &hints, &result) != 0) {
+			PLOG_WARNING << "Unable to resolve STUN server address: " << server.hostname << ':'
+			             << server.service;
 			continue;
 			continue;
+		}
 
 
 		for (auto p = result; p; p = p->ai_next) {
 		for (auto p = result; p; p = p->ai_next) {
 			if (p->ai_family == AF_INET) {
 			if (p->ai_family == AF_INET) {
@@ -423,8 +426,11 @@ IceTransport::IceTransport(const Configuration &config, Description::Role role,
 		    server.relayType == IceServer::RelayType::TurnUdp ? IPPROTO_UDP : IPPROTO_TCP;
 		    server.relayType == IceServer::RelayType::TurnUdp ? IPPROTO_UDP : IPPROTO_TCP;
 		hints.ai_flags = AI_ADDRCONFIG;
 		hints.ai_flags = AI_ADDRCONFIG;
 		struct addrinfo *result = nullptr;
 		struct addrinfo *result = nullptr;
-		if (getaddrinfo(server.hostname.c_str(), server.service.c_str(), &hints, &result) != 0)
+		if (getaddrinfo(server.hostname.c_str(), server.service.c_str(), &hints, &result) != 0) {
+			PLOG_WARNING << "Unable to resolve TURN server address: " << server.hostname << ':'
+			             << server.service;
 			continue;
 			continue;
+		}
 
 
 		for (auto p = result; p; p = p->ai_next) {
 		for (auto p = result; p; p = p->ai_next) {
 			if (p->ai_family == AF_INET || p->ai_family == AF_INET6) {
 			if (p->ai_family == AF_INET || p->ai_family == AF_INET6) {