stdio/lib_libfread: Fix buffer overflow issue
If the gulp size in the stdio buffer the remaining user buffer size it will: - Corrupt memory in dest (user memory) and - Keep corrupting KERNEL memory via the stdio character buffer until the whole system crashes, as the 'remaining' count underflows This patch fixes this behavior.
This commit is contained in:
parent
7a9d3c03e4
commit
c178fa3260
@ -126,11 +126,11 @@ ssize_t lib_fread_unlocked(FAR void *ptr, size_t count, FAR FILE *stream)
|
||||
|
||||
if (gulp_size > 0)
|
||||
{
|
||||
if (gulp_size > count)
|
||||
if (gulp_size > remaining)
|
||||
{
|
||||
/* Clip the gulp size to the requested byte count */
|
||||
|
||||
gulp_size = count;
|
||||
gulp_size = remaining;
|
||||
}
|
||||
|
||||
memcpy(dest, stream->fs_bufpos, gulp_size);
|
||||
|
Loading…
Reference in New Issue
Block a user