Fix infinite loop in ftell when writing wide char data (BZ #16398)
authorSiddhesh Poyarekar <siddhesh@redhat.com>
Wed, 5 Feb 2014 07:19:00 +0000 (12:49 +0530)
committerSiddhesh Poyarekar <siddhesh@redhat.com>
Wed, 5 Feb 2014 07:19:00 +0000 (12:49 +0530)
commitdf675f9933c5d5461cea9224ed43beddef1a7b3a
tree2a8dea7fe4b18c231b834b2c87356cb16cfeb07d
parent68159946307adfc95a6e99d1c4af5c3de0c030f9
Fix infinite loop in ftell when writing wide char data (BZ #16398)

ftell tries to avoid flushing the buffer when it is in write mode by
converting the wide char data and placing it into the binary buffer.
If the output buffer space is full and there is data to write, the
code reverts to flushing the buffer.  This breaks when there is space
in the buffer but it is not enough to convert the next character in
the wide data buffer, due to which __codecvt_do_out returns a
__codecvt_partial status.  In this case, ftell keeps running in an
infinite loop.

The fix here is to detect the __codecvt_partial status in addition to
checking if the buffer is full.  I have also added a test case that
demonstrates the infinite loop.
libio/Makefile
libio/tst-ftell-partial-wide.c [new file with mode: 0644]
libio/wfileops.c