diff options
author | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-08-13 21:00:06 -0400 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@sourceware.org> | 2024-08-28 18:44:07 -0400 |
commit | 810fa2488c140d7ae3c239fa01ec2dd61199cdc0 (patch) | |
tree | 8455c8612088a2524c3e9ea5d2a17aad8cdb700e /manual | |
parent | bb6cfec3ddcf907933fbcf650ce3fdc79c5fe797 (diff) | |
download | glibc-810fa2488c140d7ae3c239fa01ec2dd61199cdc0.zip glibc-810fa2488c140d7ae3c239fa01ec2dd61199cdc0.tar.gz glibc-810fa2488c140d7ae3c239fa01ec2dd61199cdc0.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)
(cherry picked from commit 804d3c8db79db204154dcf5e11a76f14fdddc570)
Diffstat (limited to 'manual')
-rw-r--r-- | manual/stdio.texi | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/manual/stdio.texi b/manual/stdio.texi index d7eab18..2b65485 100644 --- a/manual/stdio.texi +++ b/manual/stdio.texi @@ -1474,11 +1474,9 @@ program; usually @code{ungetc} is used only to unread a character that was just read from the same stream. @Theglibc{} supports this even on files opened in binary mode, but other systems might not. -@Theglibc{} only supports one character of pushback---in other -words, it does not work to call @code{ungetc} twice without doing input -in between. Other systems might let you push back multiple characters; -then reading from the stream retrieves the characters in the reverse -order that they were pushed. +@Theglibc{} supports pushing back multiple characters; subsequently +reading from the stream retrieves the characters in the reverse order +that they were pushed. Pushing back characters doesn't alter the file; only the internal buffering for the stream is affected. If a file positioning function |