about summary refs log tree commit diff
path: root/gshadow/sgetsgent_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'gshadow/sgetsgent_r.c')
-rw-r--r--gshadow/sgetsgent_r.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/gshadow/sgetsgent_r.c b/gshadow/sgetsgent_r.c
index 72c51fe26b..2292719af9 100644
--- a/gshadow/sgetsgent_r.c
+++ b/gshadow/sgetsgent_r.c
@@ -58,7 +58,12 @@ __sgetsgent_r (const char *string, struct sgrp *resbuf, char *buffer,
 {
   char *sp;
   if (string < buffer || string >= buffer + buflen)
-    sp = strncpy (buffer, string, buflen);
+    {
+      buffer[buflen - 1] = '\0';
+      sp = strncpy (buffer, string, buflen);
+      if (buffer[buflen - 1] != '\0')
+	return ERANGE;
+    }
   else
     sp = (char *) string;