From: Willy Tarreau Date: Thu, 29 Feb 2024 10:55:22 +0000 (+0100) Subject: MINOR: ring: make sure ring_dispatch waits when facing a changing message X-Git-Tag: v3.0-dev6~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb482f92c4caa401dbc0ed7c564efa275af3b5c1;p=thirdparty%2Fhaproxy.git MINOR: ring: make sure ring_dispatch waits when facing a changing message The writer is using tags 0xFF instead of readers count at the front of messages that are undergoing an update, while the tail has already been updated. The reader needs to take care of this because it can face these messages and mistakenly parse data that's still being written, leading to corruption (especially if this happens while the size is changing). Let's just stop reading when facing reserved codes, since they indicate that the end of usable messages was reached. --- diff --git a/src/ring.c b/src/ring.c index 963a70f31c..d0c673697e 100644 --- a/src/ring.c +++ b/src/ring.c @@ -513,6 +513,12 @@ int ring_dispatch_messages(struct ring *ring, void *ctx, size_t *ofs_ptr, size_t break; } + readers = _HA_ATOMIC_LOAD(_vp_addr(v1, v2, 0)); + if (readers > RING_MAX_READERS) { + /* we just met a writer which hasn't finished */ + break; + } + cnt = 1; len = vp_peek_varint_ofs(v1, v2, cnt, &msg_len); if (!len)