NetBSD/lib/libc/stdio
kamil 6f201b686b Avoid undefined behavior in fread(3)
On the first call to fread(3), just after fopen(3) the internal buffers
are empty. This means that _r and _p (among others) are zeroed.

Passing NULL to the 2nd argument of memcpy(3) for the zero length is
undefined. Calling _p += 0 triggers LLVM UBSan (NULL pointer arithmetic).
Calling _p += 0, p += 0 and resid -= 0 has no effect.

Replace the "fp->_r = 0;" logic with a short circuit jump to __srefill()
that sets _r internally and refills the FILE buffers.

No functional change from an end user point of view, except skipping a few
dummy operations on the first call, for a FILE pointer, to fread(3).
2020-02-22 22:02:46 +00:00
..
clrerr.c - ansify, knf. 2012-03-15 18:22:30 +00:00
dprintf.c Add explicit locale versions for the printf family. Replace asprintf, 2013-04-19 15:22:24 +00:00
fclose.3
fclose.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fdopen.c Add O_REGULAR to enforce opening of only regular files 2017-11-09 20:30:01 +00:00
feof.c - ansify, knf. 2012-03-15 18:22:30 +00:00
ferror.3 Wording. 2010-05-08 11:35:14 +00:00
ferror.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fflush.3 Document history 2019-09-07 11:53:27 +00:00
fflush.c - widen the internal read and write calls to match the syscalls 2012-03-27 15:05:42 +00:00
fgetc.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fgetln.3 Indent. 2018-07-04 07:38:38 +00:00
fgetln.c Don't use "NULL" to talk about null-terminated strings. 2017-06-08 15:59:45 +00:00
fgetpos.c From tnozaki@: make fpos_t a complex object that keeps track of the parse 2012-01-22 18:36:14 +00:00
fgets.3 Remove the note about the standard recommending fgets(3); 2010-05-13 18:38:24 +00:00
fgets.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fgetstr.c Don't use "NULL" to talk about null-terminated strings. 2017-06-08 15:59:45 +00:00
fgetwc.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fgetwln.3 Observe the following spelling: 2010-12-16 17:42:25 +00:00
fgetwln.c Improvements to fgetwln(3) from Andrey Chernov: 2016-08-27 13:15:48 +00:00
fgetws.3 Observe the following spelling: 2010-12-16 17:42:25 +00:00
fgetws.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fileext.h Use a proper char */size_t pair in __sfileext to keep track of the line 2010-01-11 20:39:29 +00:00
fileno.c - ansify, knf. 2012-03-15 18:22:30 +00:00
findfp.c - widen the internal read and write calls to match the syscalls 2012-03-27 15:05:42 +00:00
flags.c Add O_REGULAR to enforce opening of only regular files 2017-11-09 20:30:01 +00:00
floatio.h
flockfile.3 Sort SECTIONS. 2011-10-15 21:43:19 +00:00
flockfile.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fmemopen.3 English grammar nit: there's only one function described in this man page 2015-09-06 03:10:50 +00:00
fmemopen.c The flush function makes the tests fail. So undo it for now until we decide 2012-03-29 14:27:33 +00:00
fopen.3 Start documenting history 2019-09-02 00:30:58 +00:00
fopen.c Revert to commits as they broke few rump tests 2018-01-17 01:24:29 +00:00
fparseln.3 Kill unneeded paragraph macro. 2014-01-07 13:34:11 +00:00
fparseln.c Remove 3rd and 4th clauses in christos' license. OK christos. 2009-10-21 01:07:44 +00:00
fprintf.c remove diag assert - the compiler demands fp is non NULL now. 2019-01-23 00:05:47 +00:00
fpurge.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fputc.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
fputs.3 Bump date for previous. 2017-07-30 23:13:24 +00:00
fputs.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
fputwc.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fputws.3 Observe the following spelling: 2010-12-16 17:42:25 +00:00
fputws.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fread.3 .Xr for fsetpos(3), not .Fn. 2011-09-11 04:55:48 +00:00
fread.c Avoid undefined behavior in fread(3) 2020-02-22 22:02:46 +00:00
freopen.c Revert to commits as they broke few rump tests 2018-01-17 01:24:29 +00:00
fscanf.c Add scanf_l and wscanf_l families. 2013-04-19 23:32:16 +00:00
fseek.3 Fix sentences at a couple of places. 2017-01-01 12:39:33 +00:00
fseek.c Don't try to extend the offset range on 32 bit machines by treating negative 2014-11-16 20:32:52 +00:00
fseeko.c add linted comment 2017-01-10 17:44:28 +00:00
fsetpos.c From tnozaki@: make fpos_t a complex object that keeps track of the parse 2012-01-22 18:36:14 +00:00
ftell.c - widen the internal read and write calls to match the syscalls 2012-03-27 15:05:42 +00:00
ftello.c - widen the internal read and write calls to match the syscalls 2012-03-27 15:05:42 +00:00
funopen.3 Minor markup and wording fixes. 2019-03-21 21:13:45 +00:00
funopen.c PR/51572: calling funopen on each printw call is a tad excessive, but this 2016-10-23 21:01:52 +00:00
fvwrite.c - widen the internal read and write calls to match the syscalls 2012-03-27 15:05:42 +00:00
fvwrite.h PR/45989: Martin Husemann: lint invocation does include -w only on i386 2012-03-13 21:13:30 +00:00
fwalk.c - ansify, knf. 2012-03-15 18:22:30 +00:00
fwide.3
fwide.c
fwprintf.c Add explicit locale versions for the printf family. Replace asprintf, 2013-04-19 15:22:24 +00:00
fwrite.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
fwscanf.c Add scanf_l and wscanf_l families. 2013-04-19 23:32:16 +00:00
getc.3 Start documenting history 2019-09-02 00:30:58 +00:00
getc.c - ansify, knf. 2012-03-15 18:22:30 +00:00
getchar.c - ansify, knf. 2012-03-15 18:22:30 +00:00
getdelim.3 Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
getdelim.c Don't use "NULL" to talk about null-terminated strings. 2017-06-08 15:59:45 +00:00
getline.c Protect getline. 2009-12-02 08:46:33 +00:00
gets.c avoid linker warning for compat symbols that are used internally in libc, 2013-10-04 20:49:16 +00:00
gettemp.c include <sys/stat.h> 2017-01-10 17:45:12 +00:00
gettemp.h add mkostemp, mkostemps, mkstemps from FreeBSD. 2014-06-18 17:47:58 +00:00
getw.c - ansify, knf. 2012-03-15 18:22:30 +00:00
getwc.3 Remove comma after last Nm entry 2017-10-25 17:03:30 +00:00
getwc.c
getwchar.c - ansify, knf. 2012-03-15 18:22:30 +00:00
glue.h
local.h add mkostemp, mkostemps, mkstemps from FreeBSD. 2014-06-18 17:47:58 +00:00
makebuf.c Fix typo in the function comment. 2018-12-14 03:29:54 +00:00
Makefile.inc Add printf/scanf man pages from FreeBSD 2015-12-29 17:55:23 +00:00
mkdtemp.c add mkostemp, mkostemps, mkstemps from FreeBSD. 2014-06-18 17:47:58 +00:00
mkostemp.c add mkostemp, mkostemps, mkstemps from FreeBSD. 2014-06-18 17:47:58 +00:00
mkostemps.c add mkostemp, mkostemps, mkstemps from FreeBSD. 2014-06-18 17:47:58 +00:00
mkstemp.c add mkostemp, mkostemps, mkstemps from FreeBSD. 2014-06-18 17:47:58 +00:00
mkstemps.c add mkostemp, mkostemps, mkstemps from FreeBSD. 2014-06-18 17:47:58 +00:00
mktemp.3 Add all functions to NAME section. End sentences with dots. 2014-06-19 09:30:33 +00:00
mktemp.c add mkostemp, mkostemps, mkstemps from FreeBSD. 2014-06-18 17:47:58 +00:00
open_memstream.3 PR/49317: Henning Petersen: Fix prototypes inman page. 2014-10-26 14:19:28 +00:00
open_memstream.c PR/49279: Justin Cormack: add open_memstream 2014-10-13 00:40:36 +00:00
open_wmemstream.c PR/49279: Justin Cormack: add open_memstream 2014-10-13 00:40:36 +00:00
perror.c
printf_l.3 Mention stdarg.h for va_list. 2016-12-29 20:29:30 +00:00
printf.3 Fix plurals. 2017-12-31 07:22:55 +00:00
printf.c Add explicit locale versions for the printf family. Replace asprintf, 2013-04-19 15:22:24 +00:00
putc.3 putc & putw were in v1 2019-09-02 00:48:16 +00:00
putc.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
putchar.c - ansify, knf. 2012-03-15 18:22:30 +00:00
puts.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
putw.c - ansify, knf. 2012-03-15 18:22:30 +00:00
putwc.3 Observe the following spelling: 2010-12-16 17:42:25 +00:00
putwc.c
putwchar.c
refill.c - widen the internal read and write calls to match the syscalls 2012-03-27 15:05:42 +00:00
remove.3
remove.c - ansify, knf. 2012-03-15 18:22:30 +00:00
rewind.c - ansify, knf. 2012-03-15 18:22:30 +00:00
rget.c - ansify, knf. 2012-03-15 18:22:30 +00:00
scanf_l.3 Add printf/scanf man pages from FreeBSD 2015-12-29 17:55:23 +00:00
scanf.3 Fix markup 2010-05-14 03:04:32 +00:00
scanf.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
setbuf.3 Don't leave a subordinate clause out in the cold. 2018-12-14 03:43:22 +00:00
setbuf.c - ansify, knf. 2012-03-15 18:22:30 +00:00
setbuffer.c - ansify, knf. 2012-03-15 18:22:30 +00:00
setvbuf.c - ansify, knf. 2012-03-15 18:22:30 +00:00
snprintf_ss.c
sscanf.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
stdio.3 Remove extra "an" 2018-02-22 08:33:43 +00:00
stdio.c from kre: Don't fail if we are seeking on a pipe, clear the append bit 2013-05-19 17:07:04 +00:00
swprintf.c Add explicit locale versions for the printf family. Replace asprintf, 2013-04-19 15:22:24 +00:00
swscanf.c Add scanf_l and wscanf_l families. 2013-04-19 23:32:16 +00:00
tempnam.c - ansify, knf. 2012-03-15 18:22:30 +00:00
tmpfile.c - ansify, knf. 2012-03-15 18:22:30 +00:00
tmpnam.3 Refer to "w+" as "mode" as that's what fopen(3) calls it. 2019-09-01 01:23:14 +00:00
tmpnam.c - ansify, knf. 2012-03-15 18:22:30 +00:00
ungetc.3 Add HISTORY. 2010-04-30 05:56:14 +00:00
ungetc.c - ansify, knf. 2012-03-15 18:22:30 +00:00
ungetwc.3 Observe the following spelling: 2010-12-16 17:42:25 +00:00
ungetwc.c
vasprintf.c don't cast malloc 2013-05-19 21:45:00 +00:00
vdprintf.c include <sys/stat.h> 2017-01-10 17:45:12 +00:00
vfprintf.c Add explicit locale versions for the printf family. Replace asprintf, 2013-04-19 15:22:24 +00:00
vfscanf.c Provide explicit LC_C_LOCALE accessor and drop the various NULL checks. 2013-05-17 12:55:56 +00:00
vfwprintf.c A more correct fix for PR standards/52282. 2017-07-11 19:36:38 +00:00
vfwscanf.c gcc cannot always work out initialization here 2014-06-12 22:21:20 +00:00
vprintf.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
vscanf.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
vsnprintf_ss.c Return EOVERFLOW like FreeBSD does if the buffer size exceeds INT_MAX 2014-09-29 14:58:33 +00:00
vsnprintf.c undo SSP damage from -Wsystem-headers 2017-01-12 18:16:52 +00:00
vsprintf.c Provide explicit LC_C_LOCALE accessor and drop the various NULL checks. 2013-05-17 12:55:56 +00:00
vsscanf.c Provide explicit LC_C_LOCALE accessor and drop the various NULL checks. 2013-05-17 12:55:56 +00:00
vswprintf.c don't cast malloc 2013-05-19 21:45:00 +00:00
vswscanf.c Provide explicit LC_C_LOCALE accessor and drop the various NULL checks. 2013-05-17 12:55:56 +00:00
vwprintf.c Add explicit locale versions for the printf family. Replace asprintf, 2013-04-19 15:22:24 +00:00
vwscanf.c Add scanf_l and wscanf_l families. 2013-04-19 23:32:16 +00:00
wbuf.c - ansify, knf. 2012-03-15 18:22:30 +00:00
wcio.h
wprintf.3 Observe the following spelling: 2010-12-16 17:42:25 +00:00
wprintf.c Add explicit locale versions for the printf family. Replace asprintf, 2013-04-19 15:22:24 +00:00
wscanf.3 Observe the following spelling: 2010-12-16 17:42:25 +00:00
wscanf.c Add scanf_l and wscanf_l families. 2013-04-19 23:32:16 +00:00
wsetup.c - ansify, knf. 2012-03-15 18:22:30 +00:00