- fixed a bug (found by Steve Reeves) where the check for an out-of-bounds

errno was never catching illegal errnos, and thus could walk off the
  end of the message array.
This commit is contained in:
gdr-ftp 1998-02-04 15:16:19 +00:00
parent 4b239cd6da
commit e712a9ff58

View File

@ -1,7 +1,7 @@
/* /*
* Implementation by Devin Reade. * Implementation by Devin Reade.
* *
* $Id: strerror.c,v 1.2 1997/09/21 06:23:08 gdr Exp $ * $Id: strerror.c,v 1.3 1998/02/04 15:16:19 gdr-ftp Exp $
* *
* This file is formatted with tab stops every 8 columns. * This file is formatted with tab stops every 8 columns.
*/ */
@ -93,13 +93,13 @@ char *
strerror (int errnum) strerror (int errnum)
{ {
/* /*
* the size of buff must be greater than * the size of buff must be no less than
* strlen(sys_errlist[0]) + max number of digits in an int + 3 * strlen(sys_errlist[0]) + max number of digits in an int + 3
* == 13 + 5 + 3 == 21 * == 13 + 5 + 3 == 21
*/ */
static char buff[30]; static char buff[30];
if (errnum > 0 || errnum < sys_nerr) { if (errnum > 0 && errnum < sys_nerr) {
return sys_errlist[errnum]; return sys_errlist[errnum];
} }
sprintf(buff, "unknown error: %d", errnum); sprintf(buff, "unknown error: %d", errnum);