From 11f05dc09d8789e76cd58fad80c2fe64796e6101 Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Wed, 14 Mar 2012 22:37:10 +0100 Subject: [PATCH] Fix getaddrinfo() loop Commit b116d10f did the following change: Use switch, int and sa_family_t with AF_INET in uri.c. This breaks when getaddrinfo() only returns a single record, as in that case the "break" only exits the switch statement and the loop-step "res=res->ai_next" is still executed. After that "res == NULL" is wrongly interpreted as not having found an AF_INET or AF_INET6 address. Signed-off-by: Marcelo Roberto Jimenez (cherry picked from commit faaef39a3c559cc0ffc60191c7b9b5179b5ab9a3) --- upnp/src/genlib/net/uri/uri.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/upnp/src/genlib/net/uri/uri.c b/upnp/src/genlib/net/uri/uri.c index 815ffe9..0766cb7 100644 --- a/upnp/src/genlib/net/uri/uri.c +++ b/upnp/src/genlib/net/uri/uri.c @@ -388,7 +388,7 @@ static int parse_hostport( ret = getaddrinfo(srvname, NULL, &hints, &res0); if (ret == 0) { - for (res = res0; res && !ret; res = res->ai_next) { + for (res = res0; res; res = res->ai_next) { switch (res->ai_family) { case AF_INET: case AF_INET6: @@ -396,12 +396,10 @@ static int parse_hostport( memcpy(&out->IPaddress, res->ai_addr, res->ai_addrlen); - ret=1; - break; - default: - break; + goto found; } } +found: freeaddrinfo(res0); if (res == NULL) /* Didn't find an AF_INET or AF_INET6 address. */