summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/getaddrinfo.c
diff options
context:
space:
mode:
authorjinmei <jinmei@FreeBSD.org>2007-09-05 18:08:14 +0000
committerjinmei <jinmei@FreeBSD.org>2007-09-05 18:08:14 +0000
commit9bcc40000ee4195062fc66b52351f692c4089c28 (patch)
tree450615acc4a4759a553aca856aba741061918e51 /lib/libc/net/getaddrinfo.c
parentcdecabb273c2f8b867b0e440f11251cb298ff0e3 (diff)
downloadFreeBSD-src-9bcc40000ee4195062fc66b52351f692c4089c28.zip
FreeBSD-src-9bcc40000ee4195062fc66b52351f692c4089c28.tar.gz
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
Diffstat (limited to 'lib/libc/net/getaddrinfo.c')
-rw-r--r--lib/libc/net/getaddrinfo.c21
1 files changed, 19 insertions, 2 deletions
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;
OpenPOWER on IntegriCloud