summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/gethostname.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv/linux/gethostname.c')
-rw-r--r--sysdeps/unix/sysv/linux/gethostname.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/sysdeps/unix/sysv/linux/gethostname.c b/sysdeps/unix/sysv/linux/gethostname.c
index 5df8096bfd..0e3ca57aca 100644
--- a/sysdeps/unix/sysv/linux/gethostname.c
+++ b/sysdeps/unix/sysv/linux/gethostname.c
@@ -30,6 +30,7 @@ __gethostname (name, len)
      size_t len;
 {
   struct utsname buf;
+  size_t node_len;
 
   if (name == NULL)
     {
@@ -40,13 +41,14 @@ __gethostname (name, len)
   if (uname (&buf))
     return -1;
 
-  if (strlen (buf.nodename) + 1 > len)
+  node_len = strlen (buf.nodename) + 1;
+  if (node_len > len)
     {
       __set_errno (EINVAL);
       return -1;
     }
 
-  strcpy (name, buf.nodename);
+  memcpy (name, buf.nodename, node_len);
   return 0;
 }