DevSolar / pdclib

The Public Domain C Library
https://pdclib.rootdirectory.de
Creative Commons Zero v1.0 Universal
224 stars 41 forks source link

Fix PDCLib fwrite segfault #10

Closed sam-itt closed 4 years ago

sam-itt commented 4 years ago

Not resetting last seen '\n' offset after flushing the buffer (which resets the buffer index to 0) can lead to a situation where that offset has a higher value the the current buffer index, overflowing (unsigned) stream->bufidx = bufidx - offset and then doing a memmove of a gigantic size.

DevSolar commented 4 years ago

Couldn't use the pull request as my SVN repo is "master" here, but good catch, thanks. That flushbuffer in the switch should only trigger if there's a \n in there as well, so I fixed that together with the offset.

sam-itt commented 4 years ago

Great. In fact I would have sent you a patch but I couldn't find any directions on how to submit them on your website.

DevSolar commented 4 years ago

Never mind, pull requests are just fine. I wouldn't apply patches directly either; I review what the problem is and what my intentions were with the affected piece of code, and usually come up with other things to change as well, or sometimes a less invasive way to solve the problem. In any way, I usually resolve bugs by vim, not by patch. ;-)