diff --git a/ProcessUNIX.c b/ProcessUNIX.c
index 958c9d34ec3a4e649a1cc8ab0dc64da650ea4bea..0bc00b89170a3ce8a2a61d5f8eb0c1923dd31938 100644
--- a/ProcessUNIX.c
+++ b/ProcessUNIX.c
@@ -2291,6 +2291,7 @@ static void kwsysProcessChildErrorExit(int errorPipe)
   char buffer[KWSYSPE_PIPE_BUFFER_SIZE];
   kwsysProcess_ssize_t result;
   strncpy(buffer, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
+  buffer[KWSYSPE_PIPE_BUFFER_SIZE - 1] = '\0';
 
   /* Report the error to the parent through the special pipe.  */
   result = write(errorPipe, buffer, strlen(buffer));