From 644205aa076aa7a72bb60390c74b74c7b0e05978 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Thu, 16 Dec 1999 11:47:22 +0000 Subject: [PATCH] (krb5_expand_hostname): handle ai_canonname not being set git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7607 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/expand_hostname.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/krb5/expand_hostname.c b/lib/krb5/expand_hostname.c index 78cec5e58..2abd28780 100644 --- a/lib/krb5/expand_hostname.c +++ b/lib/krb5/expand_hostname.c @@ -35,6 +35,17 @@ RCSID("$Id$"); +static krb5_error_code +copy_hostname(krb5_context context, + const char *orig_hostname, + char **new_hostname) +{ + *new_hostname = strdup (orig_hostname); + if (*new_hostname == NULL) + return ENOMEM; + return 0; +} + krb5_error_code krb5_expand_hostname (krb5_context context, const char *orig_hostname, @@ -47,11 +58,11 @@ krb5_expand_hostname (krb5_context context, hints.ai_flags = AI_CANONNAME; error = getaddrinfo (orig_hostname, NULL, &hints, &ai); - if (error) { - *new_hostname = strdup (orig_hostname); - if (*new_hostname == NULL) - return ENOMEM; - return 0; + if (error) + return copy_hostname (context, orig_hostname, new_hostname); + if (ai->ai_canonname == NULL) { + freeaddrinfo (ai); + return copy_hostname (context, orig_hostname, new_hostname); } *new_hostname = strdup(ai->ai_canonname); freeaddrinfo (ai);