about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/string/strerror_r.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/string/strerror_r.c b/src/string/strerror_r.c
index 6fdd4ce2..907dcf07 100644
--- a/src/string/strerror_r.c
+++ b/src/string/strerror_r.c
@@ -4,8 +4,14 @@
 int strerror_r(int err, char *buf, size_t buflen)
 {
 	char *msg = strerror(err);
-	if (strlen(msg) >= buflen)
+	size_t l = strlen(msg);
+	if (l >= buflen) {
+		if (buflen) {
+			memcpy(buf, msg, buflen-1);
+			buf[buflen-1] = 0;
+		}
 		return ERANGE;
-	strcpy(buf, msg);
+	}
+	memcpy(buf, msg, l+1);
 	return 0;
 }