fileio: fix read_full_stream() bugs (#3887)
authorVito Caputo <vcaputo@gnugeneration.com>
Thu, 4 Aug 2016 20:52:02 +0000 (13:52 -0700)
committerLennart Poettering <lennart@poettering.net>
Thu, 4 Aug 2016 20:52:02 +0000 (22:52 +0200)
commitc2d11a630287631d3b401a5cf300ea3655e21fd1
tree57fc500bbd690aac7a08f0eca0f7d402d3a0dba6
parent80edac2090c56a72ee731f9c61ecb53d3abcb541
fileio: fix read_full_stream() bugs (#3887)

read_full_stream() _always_ allocated twice the memory needed, due to
only breaking the realloc() && fread() loop when fread() returned 0,
requiring another iteration and exponentially enlarged buffer just to
discover the EOF condition.

This also caused file sizes >2MiB && <= 4MiB to erroneously be treated
as E2BIG, due to the inappropriately doubled buffer size exceeding
4*1024*1024.

Also made the 4*1024*1024 magic number a READ_FULL_BYTES_MAX constant.
src/basic/fileio.c