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
..
Makefile.inc
clrerr.c
dprintf.c
fclose.3
fclose.c
fdopen.c Add O_REGULAR to enforce opening of only regular files 2017-11-09 20:30:01 +00:00
feof.c
ferror.3
ferror.c
fflush.3 Document history 2019-09-07 11:53:27 +00:00
fflush.c
fgetc.c
fgetln.3 Indent. 2018-07-04 07:38:38 +00:00
fgetln.c
fgetpos.c
fgets.3
fgets.c
fgetstr.c
fgetwc.c
fgetwln.3
fgetwln.c
fgetws.3
fgetws.c
fileext.h
fileno.c
findfp.c
flags.c Add O_REGULAR to enforce opening of only regular files 2017-11-09 20:30:01 +00:00
floatio.h
flockfile.3
flockfile.c
fmemopen.3
fmemopen.c
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
fparseln.c
fprintf.c remove diag assert - the compiler demands fp is non NULL now. 2019-01-23 00:05:47 +00:00
fpurge.c
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
fputws.3
fputws.c
fread.3
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
fseek.3
fseek.c
fseeko.c
fsetpos.c
ftell.c
ftello.c
funopen.3 Minor markup and wording fixes. 2019-03-21 21:13:45 +00:00
funopen.c
fvwrite.c
fvwrite.h
fwalk.c
fwide.3
fwide.c
fwprintf.c
fwrite.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
fwscanf.c
getc.3 Start documenting history 2019-09-02 00:30:58 +00:00
getc.c
getchar.c
getdelim.3
getdelim.c
getline.c
gets.c
gettemp.c
gettemp.h
getw.c
getwc.3 Remove comma after last Nm entry 2017-10-25 17:03:30 +00:00
getwc.c
getwchar.c
glue.h
local.h
makebuf.c Fix typo in the function comment. 2018-12-14 03:29:54 +00:00
mkdtemp.c
mkostemp.c
mkostemps.c
mkstemp.c
mkstemps.c
mktemp.3
mktemp.c
open_memstream.3
open_memstream.c
open_wmemstream.c
perror.c
printf.3 Fix plurals. 2017-12-31 07:22:55 +00:00
printf.c
printf_l.3
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
puts.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
putw.c
putwc.3
putwc.c
putwchar.c
refill.c
remove.3
remove.c
rewind.c
rget.c
scanf.3
scanf.c fixes for GCC 6: 2018-02-04 01:13:45 +00:00
scanf_l.3
setbuf.3 Don't leave a subordinate clause out in the cold. 2018-12-14 03:43:22 +00:00
setbuf.c
setbuffer.c
setvbuf.c
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
swprintf.c
swscanf.c
tempnam.c
tmpfile.c
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
ungetc.3
ungetc.c
ungetwc.3
ungetwc.c
vasprintf.c
vdprintf.c
vfprintf.c
vfscanf.c
vfwprintf.c A more correct fix for PR standards/52282. 2017-07-11 19:36:38 +00:00
vfwscanf.c
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.c
vsnprintf_ss.c
vsprintf.c
vsscanf.c
vswprintf.c
vswscanf.c
vwprintf.c
vwscanf.c
wbuf.c
wcio.h
wprintf.3
wprintf.c
wscanf.3
wscanf.c
wsetup.c