about summary refs log tree commit diff
path: root/nis
diff options
context:
space:
mode:
Diffstat (limited to 'nis')
-rw-r--r--nis/nis_local_names.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/nis/nis_local_names.c b/nis/nis_local_names.c
index e685255300..699ca04e66 100644
--- a/nis/nis_local_names.c
+++ b/nis/nis_local_names.c
@@ -161,15 +161,19 @@ nis_local_host (void)
 	  if (cp[-1] == '.')
 	    return __nishostname;
 
-	  if (len + strlen (nis_local_directory ()) + 1 > NIS_MAXNAMELEN)
+	  nis_name local_directory = nis_local_directory ();
+	  size_t local_directory_len = strlen (local_directory);
+	  if (len + 1 + local_directory_len > NIS_MAXNAMELEN)
 	    {
 	      __nishostname[0] = '\0';
 	      return __nishostname;
 	    }
 
+	  /* We have enough space in __nishostname with length of
+	     (NIS_MAXNAMELEN + 1) for
+	     hostname + '.' + directory-name + '\0'.  */
 	  *cp++ = '.';
-	  strncpy (cp, nis_local_directory (), NIS_MAXNAMELEN - len -1);
-	  __nishostname[NIS_MAXNAMELEN] = '\0';
+	  memcpy (cp, local_directory, local_directory_len + 1);
 	}
     }