From: Andrew Boardman Date: Wed, 16 Aug 2006 21:43:38 +0000 (+0000) Subject: Clean up string handling X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5392d3b4cce4fda0ba08b014d284d3968ac95e09;p=thirdparty%2Fkrb5.git Clean up string handling git-svn-id: svn://anonsvn.mit.edu/krb5/users/amb/referrals@18460 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c index ae3e15312e..42e6df00cf 100644 --- a/src/lib/krb5/os/hst_realm.c +++ b/src/lib/krb5/os/hst_realm.c @@ -202,7 +202,7 @@ krb5_get_host_realm(krb5_context context, const char *host, char ***realmsp) printf("get_host_realm(host:%s) called\n",host); - krb5_clean_hostname(context, host, &local_host); + krb5_clean_hostname(context, host, local_host, sizeof local_host); /* Search for the best match for the host or domain. @@ -328,7 +328,7 @@ krb5_get_fallback_host_realm(krb5_context context, const char *host, char ***rea printf("get_fallback_host_realm(host >%s<) called\n",host); - krb5_clean_hostname(context, host, &local_host); + krb5_clean_hostname(context, host, local_host, sizeof local_host); /* Scan hostname for DNS realm, and save as last-ditch realm assumption. */ @@ -411,16 +411,15 @@ krb5_get_fallback_host_realm(krb5_context context, const char *host, char ***rea * to do basic sanity checks on supplied hostname. */ krb5_error_code KRB5_CALLCONV -krb5_clean_hostname(krb5_context context, const char *host, char **local_hostp) +krb5_clean_hostname(krb5_context context, const char *host, char *local_host, size_t lhsize) { char **retrealms; - char *realm, *cp, *temp_realm, *local_host; + char *realm, *cp, *temp_realm; krb5_error_code retval; int l; - local_host=*local_hostp; - - printf("krb5_clean_hostname called: host<%s>, local_host<%s>\n",host,local_host); + local_host[0]=0; + printf("krb5_clean_hostname called: host<%s>, local_host<%s>, size %d\n",host,local_host,lhsize); if (host) { /* Filter out numeric addresses if the caller utterly failed to convert them to names. */ @@ -445,11 +444,10 @@ krb5_clean_hostname(krb5_context context, const char *host, char **local_hostp) return KRB5_ERR_NUMERIC_REALM; /* Should probably error out if strlen(host) > MAXDNAME. */ - strncpy(local_host, host, sizeof(local_host)); - local_host[sizeof(local_host) - 1] = '\0'; + strncpy(local_host, host, lhsize); + local_host[lhsize - 1] = '\0'; } else { - retval = krb5int_get_fq_local_hostname (local_host, - sizeof (local_host)); + retval = krb5int_get_fq_local_hostname (local_host, lhsize); if (retval) return retval; } @@ -464,6 +462,6 @@ krb5_clean_hostname(krb5_context context, const char *host, char **local_hostp) if (l && local_host[l-1] == '.') local_host[l-1] = 0; - printf("krb5_clean_hostname ending: host<%s>, local_host<%s>\n",host,local_host); + printf("krb5_clean_hostname ending: host<%s>, local_host<%s>, size %d\n",host,local_host,lhsize); return 0; }