]> git.pond.sub.org Git - empserver/commit
client: Fix integer wrap around in ring_peek()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 27 Dec 2015 14:32:00 +0000 (15:32 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 8 Jul 2017 17:17:07 +0000 (19:17 +0200)
commit63a6288435c35cd628abd530e0dc3bf84168c2e0
treee633357d8289d0bdd6de84a4bd962bfcfef7f907
parent93dfd60c4bccdc9ee227e0fd8034e27134896735
client: Fix integer wrap around in ring_peek()

Peeking beyond either end of the ring buffer must return EOF.  We
first compute the index, then check whether it's in range.

Unfortunately, the index computation r->prod - -n can wrap around
while r->prod is still <= RING_SIZE.  If it happens, ring_peek()
returns r->buf[(r->prod - -n) % RING_SIZE] instead of EOF.

Currently harmless, because no caller peeks out of range.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/client/ringbuf.c