c6a96a8441
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 |
||
---|---|---|
.. | ||
_flock_stub.c | ||
asprintf.c | ||
clrerr.c | ||
dprintf.c | ||
fclose.3 | ||
fclose.c | ||
fcloseall.c | ||
fdopen.c | ||
feof.c | ||
ferror.3 | ||
ferror.c | ||
fflush.3 | ||
fflush.c | ||
fgetc.c | ||
fgetln.3 | ||
fgetln.c | ||
fgetpos.c | ||
fgets.3 | ||
fgets.c | ||
fgetwc.c | ||
fgetwln.3 | ||
fgetwln.c | ||
fgetws.3 | ||
fgetws.c | ||
fileno.c | ||
findfp.c | ||
flags.c | ||
floatio.h | ||
flockfile.3 | ||
fopen.3 | ||
fopen.c | ||
fprintf.c | ||
fpurge.c | ||
fputc.c | ||
fputs.3 | ||
fputs.c | ||
fputwc.c | ||
fputws.3 | ||
fputws.c | ||
fread.3 | ||
fread.c | ||
freopen.c | ||
fscanf.c | ||
fseek.3 | ||
fseek.c | ||
fsetpos.c | ||
ftell.c | ||
funopen.3 | ||
funopen.c | ||
fvwrite.c | ||
fvwrite.h | ||
fwalk.c | ||
fwide.3 | ||
fwide.c | ||
fwprintf.c | ||
fwrite.c | ||
fwscanf.c | ||
getc.3 | ||
getc.c | ||
getchar.c | ||
getdelim.c | ||
getline.3 | ||
getline.c | ||
gets.c | ||
getw.c | ||
getwc.3 | ||
getwc.c | ||
getwchar.c | ||
glue.h | ||
local.h | ||
makebuf.c | ||
Makefile.inc | ||
mktemp.3 | ||
mktemp.c | ||
perror.c | ||
printf-pos.c | ||
printf.3 | ||
printf.c | ||
printfcommon.h | ||
printflocal.h | ||
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 | ||
sscanf.c | ||
stdio.3 | ||
stdio.c | ||
swprintf.c | ||
swscanf.c | ||
Symbol.map | ||
tempnam.c | ||
tmpfile.c | ||
tmpnam.3 | ||
tmpnam.c | ||
ungetc.3 | ||
ungetc.c | ||
ungetwc.3 | ||
ungetwc.c | ||
vasprintf.c | ||
vdprintf.c | ||
vfprintf.c | ||
vfscanf.c | ||
vfwprintf.c | ||
vfwscanf.c | ||
vprintf.c | ||
vscanf.c | ||
vsnprintf.c | ||
vsprintf.c | ||
vsscanf.c | ||
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 | ||
xprintf_vis.c | ||
xprintf.c |