summaryrefslogtreecommitdiff
path: root/src/stdio/ungetc.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2023-03-20 18:48:20 -0400
committerRich Felker <dalias@aerifal.cx>2023-03-21 09:10:11 -0400
commit0440ed69eac766c712e974358c3e09d63e330f40 (patch)
tree89c12b1b0467a4e4ec6b7520c94b646eb837adf7 /src/stdio/ungetc.c
parentd055e6a45a17673b8dd3ec16e786bb2fe1700dd5 (diff)
downloadmusl-0440ed69eac766c712e974358c3e09d63e330f40.tar.gz
musl-0440ed69eac766c712e974358c3e09d63e330f40.tar.bz2
musl-0440ed69eac766c712e974358c3e09d63e330f40.tar.xz
musl-0440ed69eac766c712e974358c3e09d63e330f40.zip
fix wide printf continuation after output or encoding errors
this fixes a broader bug for which a special case was reported by Bruno Haible, in the form of %n getting processed (and reporting the number of wide characters which would have been written, but weren't) after an encoding error (EILSEQ). in addition to the %n case, some but not all of the format specifiers continued to attempt output after an error. in particular, %c, %lc, and %s all used fputwc directly without any check for error status. as long as the error condition was permanent rather than transient, these write attempts had no visible side effects, but in theory it could be visible, for example with EAGAIN/EWOULDBLOCK or ENOSPC, if the condition precluding output came to an end. this could produce output with missing non-final data, rather than just truncated output, albeit with the function still returning -1 as expected to report an error. to fix this, a check is added to stop processing of any new directive (including %n) if the stream is already in error state, and direct use of fputwc is replaced with calls to the out() helper function, which checks for error status. note that fprintf is also used directly without checking error status, but due to how commit d42269d7c85308abdbf8cee38b1a1097249eb38b previously attempted to solve the issue of output after error, the call to fprintf does not attempt to write anything when the wide-oriented stream is already in error state. this is non-obvious, and is quite a hack, so it should be changed, but I've left it alone for now to make the bug fix commit itself as non-invasive as possible.
Diffstat (limited to 'src/stdio/ungetc.c')
0 files changed, 0 insertions, 0 deletions