From 1bf4289d86388e446fda46c45acc2f05632c64ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Mon, 25 Aug 2008 02:33:28 +0000 Subject: [PATCH] Check return value of gethostname() and truncate string. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23675 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/principal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/krb5/principal.c b/lib/krb5/principal.c index bcc7b23b7..3a1d184c3 100644 --- a/lib/krb5/principal.c +++ b/lib/krb5/principal.c @@ -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)