summaryrefslogtreecommitdiffstats
path: root/lib/libc/string/strerror_r.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2005-05-08 06:25:44 +0000
committerotto <otto@openbsd.org>2005-05-08 06:25:44 +0000
commitd4786f81817d9d1616a47cefb7f48fcec8f57ca5 (patch)
tree4c666aacfed899fc8c06d49336c1aecfbeb7704c /lib/libc/string/strerror_r.c
parentSimplify loop reconfiguration code. (diff)
downloadwireguard-openbsd-d4786f81817d9d1616a47cefb7f48fcec8f57ca5.tar.xz
wireguard-openbsd-d4786f81817d9d1616a47cefb7f48fcec8f57ca5.zip
Only append number when it fits to avoid truncation and return
appropriate error number. ok miod@, millert@ on an earlier version; ok jaredey@
Diffstat (limited to 'lib/libc/string/strerror_r.c')
-rw-r--r--lib/libc/string/strerror_r.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/libc/string/strerror_r.c b/lib/libc/string/strerror_r.c
index c0ca434cbde..28bfd00a47e 100644
--- a/lib/libc/string/strerror_r.c
+++ b/lib/libc/string/strerror_r.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: strerror_r.c,v 1.3 2005/04/20 23:38:15 beck Exp $ */
+/* $OpenBSD: strerror_r.c,v 1.4 2005/05/08 06:25:44 otto Exp $ */
/* Public Domain <marc@snafu.org> */
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: strerror_r.c,v 1.3 2005/04/20 23:38:15 beck Exp $";
+static char *rcsid = "$OpenBSD: strerror_r.c,v 1.4 2005/05/08 06:25:44 otto Exp $";
#endif /* LIBC_SCCS and not lint */
#ifdef NLS
@@ -32,7 +32,7 @@ __digits10(unsigned int num)
return i;
}
-static void
+static int
__itoa(int num, char *buffer, size_t start, size_t end)
{
size_t pos;
@@ -54,21 +54,17 @@ __itoa(int num, char *buffer, size_t start, size_t end)
if (pos < end)
buffer[pos] = '\0';
- else {
- if (end)
- buffer[--end] = '\0'; /* XXX */
- }
+ else
+ return ERANGE;
pos--;
do {
-
- if (pos < end)
- buffer[pos] = (a % 10) + '0';
+ buffer[pos] = (a % 10) + '0';
pos--;
a /= 10;
} while (a != 0);
if (neg)
- if (pos < end)
- buffer[pos] = '-';
+ buffer[pos] = '-';
+ return 0;
}
@@ -110,8 +106,9 @@ strerror_r(int errnum, char *strerrbuf, size_t buflen)
if (len >= buflen)
ret_errno = ERANGE;
else {
- __itoa(errnum, strerrbuf, len, buflen);
- ret_errno = EINVAL;
+ ret_errno = __itoa(errnum, strerrbuf, len, buflen);
+ if (ret_errno == 0)
+ ret_errno = EINVAL;
}
}