Implement a simple bound-checker in RingBufWrite():
if the ringbuf is shared among multiple threads (e.g. the sbbs->outbuf is shared between output_thread() and passthru_thread()) - it was possible for a race condition to occur between the caller would call RingBufFree to determine the available space in the ringbuf and the call to RingBufWrite which would happily overflow the allocated buffer if more data was written to the ringbuf (by another thread) in the unprotected time between the RingBufFree and RingBufWrite calls. Now, RingBufWrite() can perform short-writes and will return a length less than what was requested to write when there is not enough available space to write the requested length. Hopefully this resolves the corruption/crash issue Deuce is seeing in sbbs's passthru_thread().
Showing with 4 additions and 5 deletions