]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ring: make sure ring_dispatch waits when facing a changing message
authorWilly Tarreau <w@1wt.eu>
Thu, 29 Feb 2024 10:55:22 +0000 (11:55 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Mar 2024 17:34:19 +0000 (17:34 +0000)
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.

src/ring.c

index 963a70f31cdd9c7c402b187ccc00df0153c49696..d0c673697e710f124ff5f41ad716c8148785e74d 100644 (file)
@@ -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)