From: Mathieu Desnoyers Date: Tue, 19 Feb 2019 22:47:49 +0000 (-0500) Subject: Fix: consumer snapshot: handle unsigned long overflow X-Git-Tag: v2.10.7~21 X-Git-Url: http://git.liburcu.org/?p=lttng-tools.git;a=commitdiff_plain;h=a578f62ffe6b2f2dbbdf804bc6e07ec8b38f02e6 Fix: consumer snapshot: handle unsigned long overflow Comparing the consumed iterator and the produced position without using a difference generates an empty snapshot when the iterator is before unsigned long overflow and the produced position is after unsigned long overflow. This applies to both UST and kernel consumers. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index d82e07fca..d44ee6a7d 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -240,7 +240,7 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path, produced_pos, nb_packets_per_stream, stream->max_sb_size); - while (consumed_pos < produced_pos) { + while ((long) (consumed_pos - produced_pos) < 0) { ssize_t read_len; unsigned long len, padded_len; diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 3d3a30dcd..cc77739ce 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -1174,7 +1174,7 @@ static int snapshot_channel(uint64_t key, char *path, uint64_t relayd_id, produced_pos, nb_packets_per_stream, stream->max_sb_size); - while (consumed_pos < produced_pos) { + while ((long) (consumed_pos - produced_pos) < 0) { ssize_t read_len; unsigned long len, padded_len;