From 1ef68eeb3186b78a0807421505d2044258dcbb3e Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 17 May 2018 12:29:04 +0100 Subject: [PATCH] capture: do 24 bit counter identifier checks Max uint was more than we allow, since we steal the top 8 bits for some other data. This instead checks for 24-bit and warns if the user tries to store a counter value that was not registered. --- lib/capture/sp-capture-writer.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/capture/sp-capture-writer.c b/lib/capture/sp-capture-writer.c index d61490d2..f29bfb75 100644 --- a/lib/capture/sp-capture-writer.c +++ b/lib/capture/sp-capture-writer.c @@ -34,6 +34,7 @@ #define DEFAULT_BUFFER_SIZE (getpagesize() * 64L) #define INVALID_ADDRESS (G_GUINT64_CONSTANT(0)) +#define MAX_COUNTERS ((1 << 24) - 1) typedef struct { @@ -1079,7 +1080,15 @@ sp_capture_writer_define_counters (SpCaptureWriter *self, def->n_counters = n_counters; for (i = 0; i < n_counters; i++) - def->counters[i] = counters[i]; + { + if (counters[i].id >= self->next_counter_id) + { + g_warning ("Counter %u has not been registered.", counters[i].id); + continue; + } + + def->counters[i] = counters[i]; + } self->stat.frame_count[SP_CAPTURE_FRAME_CTRDEF]++; @@ -1171,7 +1180,7 @@ sp_capture_writer_request_counter (SpCaptureWriter *self, g_assert (self != NULL); - if (G_MAXUINT - n_counters < self->next_counter_id) + if (MAX_COUNTERS - n_counters < self->next_counter_id) return 0; ret = self->next_counter_id;