Check return value of gethostname in krb5_klog_init
authorGreg Hudson <ghudson@mit.edu>
Mon, 23 Nov 2009 19:24:42 +0000 (19:24 +0000)
committerGreg Hudson <ghudson@mit.edu>
Mon, 23 Nov 2009 19:24:42 +0000 (19:24 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23313 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/kadm5/logger.c

index b8da20955b764869fffeeea3c4b4995c25dfb4a4..a3f4339104cfcbabe992a9411156486943eda3d4 100644 (file)
@@ -668,8 +668,11 @@ krb5_klog_init(krb5_context kcontext, char *ename, char *whoami, krb5_boolean do
         log_control.log_whoami = strdup(whoami);
         log_control.log_hostname = (char *) malloc(MAXHOSTNAMELEN + 1);
         if (log_control.log_hostname) {
-            gethostname(log_control.log_hostname, MAXHOSTNAMELEN);
-            log_control.log_hostname[MAXHOSTNAMELEN] = '\0';
+            if (gethostname(log_control.log_hostname, MAXHOSTNAMELEN) == -1) {
+                free(log_control.log_hostname);
+                log_control.log_hostname = NULL;
+            } else
+                log_control.log_hostname[MAXHOSTNAMELEN] = '\0';
         }
 #ifdef  HAVE_OPENLOG
         if (do_openlog) {