]> sourceware.org Git - glibc.git/commit
ungetc: Fix uninitialized read when putting into unused streams [BZ #27821]
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Wed, 14 Aug 2024 01:00:06 +0000 (21:00 -0400)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Thu, 15 Aug 2024 17:55:07 +0000 (13:55 -0400)
commitcdf0f88f97b0aaceb894cc02b21159d148d7065c
treeed6685cb305c34086c790abd40d3475a2a72e26d
parent3f7df7e757f4efec38e45d4068e5492efcac4856
ungetc: Fix uninitialized read when putting into unused streams [BZ #27821]

When ungetc is called on an unused stream, the backup buffer is
allocated without the main get area being present.  This results in
every subsequent ungetc (as the stream remains in the backup area)
checking uninitialized memory in the backup buffer when trying to put a
character back into the stream.

Avoid comparing the input character with buffer contents when in backup
to avoid this uninitialized read.  The uninitialized read is harmless in
this context since the location is promptly overwritten with the input
character, thus fulfilling ungetc functionality.

Also adjust wording in the manual to drop the paragraph that says glibc
cannot do multiple ungetc back to back since with this change, ungetc
can actually do this.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
libio/genops.c
manual/stdio.texi
stdio-common/tst-ungetc.c
This page took 0.038699 seconds and 5 git commands to generate.