fwrite can loop forever on zero byte write
The different stdio write paths all have their own implementation of writing to the underlying object and the interim buffer. While working on the memory streams, if a write is beyond the end of a fixed buffer with fmemstream(3C), you are supposed to return a zero byte write. While most of the other places this occurs handle a zero-byte write correctly, fwrite() does not. This in turn leads to the code infinite looping. This probably has not been an issue as it is rare for write(2) to return zero. The solution is just to treat this like the other cases. While we should consolidate the underlying write implementations I didn't want to do that at this time since there was enough other stuff going on with the support of memory streams.
Updated by Electric Monk about 1 year ago
- Status changed from New to Closed
- % Done changed from 90 to 100
commit cd62a92d4a964bfe61d35ba2301b69e65e22a509 Author: Robert Mustacchi <firstname.lastname@example.org> Date: 2020-03-26T07:42:53.000Z 7092 Want support for stdio memory streams 12360 fwrite can loop forever on zero byte write 12392 ftello64 doesn't handle ungetc() correctly when unbuffered Reviewed by: John Levon <email@example.com> Reviewed by: Yuri Pankov <firstname.lastname@example.org> Approved by: Dan McDonald <email@example.com>