diff options
| author | jtc <jtc@NetBSD.org> | 1996-10-11 00:51:07 +0000 |
|---|---|---|
| committer | jtc <jtc@NetBSD.org> | 1996-10-11 00:51:07 +0000 |
| commit | ace90ad26bdcc4adceddaddf8e80581e1a7cc3b6 (patch) | |
| tree | 7e6e5c4a4abd84636d0e95bb04cc9f67820e11b9 /lib/libc/string | |
| parent | 19d8368f2fb188a3604c490bbde75418e6da04a1 (diff) | |
Since the user provide his own message catalog (via NLSPATH and LANG)
the __strerror() and __strsignal() functions can not assume that the
messages will not overflow a NL_TEXTSIZE-sized buffer.
Noted by Mike Long <mike.long@analog.com> in PR
Diffstat (limited to 'lib/libc/string')
| -rw-r--r-- | lib/libc/string/__strerror.c | 11 | ||||
| -rw-r--r-- | lib/libc/string/__strsignal.c | 11 |
2 files changed, 14 insertions, 8 deletions
diff --git a/lib/libc/string/__strerror.c b/lib/libc/string/__strerror.c index b147ac63e1e..65833f11c99 100644 --- a/lib/libc/string/__strerror.c +++ b/lib/libc/string/__strerror.c @@ -33,13 +33,14 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ -static char *rcsid = "$Id: __strerror.c,v 1.7 1996/01/20 01:41:51 jtc Exp $"; +static char *rcsid = "$Id: __strerror.c,v 1.8 1996/10/11 00:51:07 jtc Exp $"; #endif /* LIBC_SCCS and not lint */ #ifdef NLS #define catclose _catclose #define catgets _catgets #define catopen _catopen +#include <limits.h> #include <nl_types.h> #endif @@ -72,14 +73,16 @@ __strerror(num, buf) errnum = num; /* convert to unsigned */ if (errnum < sys_nerr) { #ifdef NLS - strcpy(buf, catgets(catd, 1, errnum, - (char *)sys_errlist[errnum])); + strncpy(buf, catgets(catd, 1, errnum, + (char *)sys_errlist[errnum]), NL_TEXTMAX); + buf[NL_TEXTMAX - 1] = '\0'; #else return(sys_errlist[errnum]); #endif } else { #ifdef NLS - sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), errnum); + snprintf(buf, NL_TEXTMAX, + catgets(catd, 1, 0xffff, UPREFIX), errnum); #else sprintf(buf, UPREFIX, errnum); #endif diff --git a/lib/libc/string/__strsignal.c b/lib/libc/string/__strsignal.c index d0dc9eaa2b1..ad14117057a 100644 --- a/lib/libc/string/__strsignal.c +++ b/lib/libc/string/__strsignal.c @@ -33,13 +33,14 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)strerror.c 5.6 (Berkeley) 5/4/91";*/ -static char *rcsid = "$Id: __strsignal.c,v 1.9 1995/06/15 00:07:11 jtc Exp $"; +static char *rcsid = "$Id: __strsignal.c,v 1.10 1996/10/11 00:51:08 jtc Exp $"; #endif /* LIBC_SCCS and not lint */ #ifdef NLS #define catclose _catclose #define catgets _catgets #define catopen _catopen +#include <limits.h> #include <nl_types.h> #endif @@ -65,14 +66,16 @@ __strsignal(num, buf) signum = num; /* convert to unsigned */ if (signum < NSIG) { #ifdef NLS - strcpy(buf, catgets(catd, 2, signum, - (char *)sys_siglist[signum])); + stnrcpy(buf, catgets(catd, 2, signum, + (char *)sys_siglist[signum]), NL_TEXTMAX); + buf[NL_TEXTMAX - 1] = '\0'; #else return((char *)sys_siglist[signum]); #endif } else { #ifdef NLS - sprintf(buf, catgets(catd, 1, 0xffff, UPREFIX), signum); + snprintf(buf, NL_TEXTMAX, + catgets(catd, 1, 0xffff, UPREFIX), signum); #else sprintf(buf, UPREFIX, signum); #endif |
