freebsd-skq/lib/libc/stdio
Colin Percival c6a96a8441 Give a less silly response to a silly request.
Prior to this commit, fread/fwrite calls with size * nmemb > SIZE_MAX
were handled by reading or writing (size_t)(size * nmemb) bytes; for
example, on 32-bit platforms, fread(ptr, 641, 6700417, f) would read 1
byte and indicate that the requested 6700417 blocks had been read.

This commit adds a check for such integer overflows, and treats them as
if an overly large request was passed to read/write; i.e., it sets errno
to EINVAL, sets the error indicator on the file, and returns a short
object count (0, to be specific).

The overflow check involves an integer division, so as a performance
optimization we check first to see if both size and nmemb are less than
2^16; if they are, no overflow is possible and we avoid the division.
We assume here that size_t is at least 32 bits; this appears to be true
on all platforms FreeBSD supports.

Although this commit fixes an integer overflow, it is not likely to have
any security implications, since any program which would be affected by
this bug fix is quite clearly already very confused.

Reviewed by:	kib
MFC after:	1 month
2010-01-10 14:30:30 +00:00
..
_flock_stub.c
asprintf.c Rewrite asprintf() as a wrapper around vasprintf(), thus reducing the 2009-03-02 04:11:42 +00:00
clrerr.c
dprintf.c Add dprintf() and vdprintf() from POSIX.1-2008. Like getline(), 2009-03-04 03:38:51 +00:00
fclose.3
fclose.c
fcloseall.c
fdopen.c
feof.c
ferror.3
ferror.c
fflush.3
fflush.c
fgetc.c
fgetln.3 - Add getdelim(), getline(), stpncpy(), strnlen(), wcsnlen(), 2009-02-28 06:00:58 +00:00
fgetln.c
fgetpos.c
fgets.3 - Add getdelim(), getline(), stpncpy(), strnlen(), wcsnlen(), 2009-02-28 06:00:58 +00:00
fgets.c
fgetwc.c
fgetwln.3
fgetwln.c
fgetws.3
fgetws.c Eliminate more dead stores. 2009-11-25 04:45:45 +00:00
fileno.c
findfp.c Fix many "function declaration isn't a prototype" warnings in libc. 2009-12-05 19:31:38 +00:00
flags.c
floatio.h
flockfile.3
fopen.3 Make the description of `b' a little better. 2009-09-09 19:38:19 +00:00
fopen.c
fprintf.c
fpurge.c
fputc.c
fputs.3
fputs.c
fputwc.c
fputws.3
fputws.c
fread.3
fread.c Give a less silly response to a silly request. 2010-01-10 14:30:30 +00:00
freopen.c
fscanf.c
fseek.3
fseek.c
fsetpos.c
ftell.c
funopen.3
funopen.c Fix many "function declaration isn't a prototype" warnings in libc. 2009-12-05 19:31:38 +00:00
fvwrite.c Eliminate dead store. 2009-11-25 04:21:42 +00:00
fvwrite.h
fwalk.c
fwide.3
fwide.c
fwprintf.c
fwrite.c Give a less silly response to a silly request. 2010-01-10 14:30:30 +00:00
fwscanf.c
getc.3 Remove unnecessary quoting and markup, add missing punctuation. 2010-01-08 22:02:42 +00:00
getc.c
getchar.c
getdelim.c Better glibc compatibility for getline/getdelim: 2009-10-04 19:43:36 +00:00
getline.3 2009-12-16 04:19:23 +00:00
getline.c - Add getdelim(), getline(), stpncpy(), strnlen(), wcsnlen(), 2009-02-28 06:00:58 +00:00
gets.c
getw.c
getwc.3
getwc.c
getwchar.c
glue.h
local.h
makebuf.c
Makefile.inc Add dprintf() and vdprintf() from POSIX.1-2008. Like getline(), 2009-03-04 03:38:51 +00:00
mktemp.3
mktemp.c
perror.c
printf-pos.c The argument corresponding to %zn is supposed to be an ssize_t *, not 2009-03-02 04:07:58 +00:00
printf.3 Fix the dprintf() prototype. 2009-12-02 07:51:25 +00:00
printf.c
printfcommon.h
printflocal.h The argument corresponding to %zn is supposed to be an ssize_t *, not 2009-03-02 04:07:58 +00:00
putc.3
putc.c
putchar.c
puts.c
putw.c
putwc.3
putwc.c
putwchar.c
refill.c
remove.3
remove.c
rewind.c
rget.c
scanf.3
scanf.c
setbuf.3
setbuf.c
setbuffer.c
setvbuf.c
snprintf.c
sprintf.c Use vsprintf instead of rolling our own. 2009-12-21 19:59:38 +00:00
sscanf.c Use vsscanf instead of rolling our own. 2009-12-21 19:56:03 +00:00
stdio.3 Add dprintf() and vdprintf() from POSIX.1-2008. Like getline(), 2009-03-04 03:38:51 +00:00
stdio.c
swprintf.c
swscanf.c
Symbol.map Add dprintf() and vdprintf() from POSIX.1-2008. Like getline(), 2009-03-04 03:38:51 +00:00
tempnam.c
tmpfile.c
tmpnam.3
tmpnam.c
ungetc.3
ungetc.c
ungetwc.3
ungetwc.c
vasprintf.c
vdprintf.c Add dprintf() and vdprintf() from POSIX.1-2008. Like getline(), 2009-03-04 03:38:51 +00:00
vfprintf.c Replace a dozen lines of code with a call to strnlen() / wcsnlen(). 2009-02-28 06:06:57 +00:00
vfscanf.c
vfwprintf.c In __mbsconv(), if prec was zero, nconv could have been used 2009-11-25 04:27:55 +00:00
vfwscanf.c
vprintf.c
vscanf.c
vsnprintf.c
vsprintf.c
vsscanf.c K&R -> ANSI prototype. 2009-12-21 19:55:05 +00:00
vswprintf.c
vswscanf.c
vwprintf.c
vwscanf.c
wbuf.c
wprintf.3
wprintf.c
wscanf.3
wscanf.c
wsetup.c
xprintf_errno.c
xprintf_float.c
xprintf_hexdump.c
xprintf_int.c
xprintf_quote.c
xprintf_str.c
xprintf_time.c Make all three if conditions look similar by always initializing nsec 2009-11-25 04:35:54 +00:00
xprintf_vis.c
xprintf.c