diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-08-13 21:00:06 -0400 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-08-28 15:58:01 -0400 |
commit | 70939528c67507f12d6d41423b7fac25153a6dce (patch) | |
tree | 02d0b9b39bbb791b0bf128e10ecd57fb93b982ae /libio | |
parent | f0c308ab239340190f5ca9a226e43f3041d487f7 (diff) | |
download | glibc-70939528c67507f12d6d41423b7fac25153a6dce.zip glibc-70939528c67507f12d6d41423b7fac25153a6dce.tar.gz glibc-70939528c67507f12d6d41423b7fac25153a6dce.tar.bz2 |
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>
(cherry picked from commit cdf0f88f97b0aaceb894cc02b21159d148d7065c)
Diffstat (limited to 'libio')
-rw-r--r-- | libio/genops.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libio/genops.c b/libio/genops.c index bc45e60..4f5c613 100644 --- a/libio/genops.c +++ b/libio/genops.c @@ -635,7 +635,7 @@ _IO_sputbackc (FILE *fp, int c) { int result; - if (fp->_IO_read_ptr > fp->_IO_read_base + if (fp->_IO_read_ptr > fp->_IO_read_base && !_IO_in_backup (fp) && (unsigned char)fp->_IO_read_ptr[-1] == (unsigned char)c) { fp->_IO_read_ptr--; |