From 9bcc40000ee4195062fc66b52351f692c4089c28 Mon Sep 17 00:00:00 2001 From: jinmei Date: Wed, 5 Sep 2007 18:08:14 +0000 Subject: ensure the head entry of addrinfo chain has non-NULL ai_canonname to be compliant with RFC3493. PR: standards/114910 Approved by: ume (mentor) Approved by: re MFC after: 1 week --- lib/libc/net/getaddrinfo.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index 11742b9..60be685 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -575,11 +575,28 @@ good: * If the returned entry is for an active connection, * and the given name is not numeric, reorder the * list, so that the application would try the list - * in the most efficient order. + * in the most efficient order. Since the head entry + * of the original list may contain ai_canonname and + * that entry may be moved elsewhere in the new list, + * we keep the pointer and will restore it in the new + * head entry. (Note that RFC3493 requires the head + * entry store it when requested by the caller). */ if (hints == NULL || !(hints->ai_flags & AI_PASSIVE)) { - if (!numeric) + if (!numeric) { + char *canonname; + + canonname = + sentinel.ai_next->ai_canonname; + sentinel.ai_next->ai_canonname = NULL; (void)reorder(&sentinel); + if (sentinel.ai_next->ai_canonname == + NULL) { + sentinel.ai_next->ai_canonname + = canonname; + } else if (canonname != NULL) + free(canonname); + } } *res = sentinel.ai_next; return SUCCESS; -- cgit v1.1