Check return value of gethostname() and truncate string.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23675 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2008-08-25 02:33:28 +00:00
parent 3a00ceaf3d
commit 1bf4289d86

View File

@@ -1259,7 +1259,14 @@ krb5_sname_to_principal (krb5_context context,
return KRB5_SNAME_UNSUPP_NAMETYPE;
}
if(hostname == NULL) {
gethostname(localhost, sizeof(localhost));
ret = gethostname(localhost, sizeof(localhost) - 1);
if (ret != 0) {
ret = errno;
krb5_set_error_message(context, ret,
"Failed to get local hostname");
return ret;
}
localhost[sizeof(localhost) - 1] = '\0';
hostname = localhost;
}
if(sname == NULL)