diff options
author | Ulrich Drepper <drepper@gmail.com> | 2011-05-21 12:11:36 -0400 |
---|---|---|
committer | Ulrich Drepper <drepper@gmail.com> | 2011-05-21 12:11:36 -0400 |
commit | 7ea72f99966a65a56aedba817ee2413ff9b1f23c (patch) | |
tree | b5e30f57554d3999654fff7fc2223dffc4d167fb /string | |
parent | 7e4afad5bcf49e03c3b987399c6a8f66a9018660 (diff) | |
download | glibc-7ea72f99966a65a56aedba817ee2413ff9b1f23c.zip glibc-7ea72f99966a65a56aedba817ee2413ff9b1f23c.tar.gz glibc-7ea72f99966a65a56aedba817ee2413ff9b1f23c.tar.bz2 |
Always fill output buffer in XPG strerror function
Diffstat (limited to 'string')
-rw-r--r-- | string/xpg-strerror.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/string/xpg-strerror.c b/string/xpg-strerror.c index 8d89812..00256c3 100644 --- a/string/xpg-strerror.c +++ b/string/xpg-strerror.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1993, 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2010 +/* Copyright (C) 1991, 1993, 1995-1998, 2000, 2002, 2004, 2010, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -17,6 +17,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <assert.h> #include <errno.h> #include <libintl.h> #include <stdio.h> @@ -37,16 +38,16 @@ int __xpg_strerror_r (int errnum, char *buf, size_t buflen) { + const char *estr = __strerror_r (errnum, buf, buflen); + size_t estrlen = strlen (estr); + if (errnum < 0 || errnum >= _sys_nerr_internal || _sys_errlist_internal[errnum] == NULL) return EINVAL; - const char *estr = (const char *) _(_sys_errlist_internal[errnum]); - size_t estrlen = strlen (estr) + 1; - - if (buflen < estrlen) - return ERANGE; + assert (estr != buf); +/* Terminate the string in any case. */ + *((char *) __mempcpy (buf, estr, MIN (buflen - 1, estrlen))) = '\0'; - memcpy (buf, estr, estrlen); - return 0; + return buflen <= estrlen ? ERANGE : 0; } |