summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2005-05-08 06:25:45 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2005-05-08 06:25:45 +0000
commit1203a91023303369e685c9b321ea63a821b906d9 (patch)
treeb0b59aaf14466f30bb23d0b1ffdf0acc2f940e0e /lib/libc
parentbfee6ea4078b7804a9d191cc74f080ddf73184f6 (diff)
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')
-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;
}
}