From 4080b9e6cd272301077d85b5bfb79d5e76cc3864 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 29 Apr 2020 11:59:02 +0200 Subject: [PATCH] BUG/MEDIUM: sample: make the CPU and latency sample fetches check for a stream cpu_calls, cpu_ns_avg, cpu_ns_tot, lat_ns_avg and lat_ns_tot depend on the stream to find the current task and must check for it or they may cause a crash if misused or used in a log-format string after commit 5f940703b3 ("MINOR: log: Don't depends on a stream to process samples in log-format string"). This must be backported as far as 1.9. (cherry picked from commit e0dd210cea36972a6f566b9b49d8f0c33340df99) Signed-off-by: Willy Tarreau --- src/sample.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sample.c b/src/sample.c index 90831d1..7362a2d 100644 --- a/src/sample.c +++ b/src/sample.c @@ -3144,6 +3144,9 @@ smp_fetch_stopping(const struct arg *args, struct sample *smp, const char *kw, v static int smp_fetch_cpu_calls(const struct arg *args, struct sample *smp, const char *kw, void *private) { + if (!smp->strm) + return 0; + smp->data.type = SMP_T_SINT; smp->data.u.sint = smp->strm->task->calls; return 1; @@ -3153,6 +3156,9 @@ smp_fetch_cpu_calls(const struct arg *args, struct sample *smp, const char *kw, static int smp_fetch_cpu_ns_avg(const struct arg *args, struct sample *smp, const char *kw, void *private) { + if (!smp->strm) + return 0; + smp->data.type = SMP_T_SINT; smp->data.u.sint = smp->strm->task->calls ? smp->strm->task->cpu_time / smp->strm->task->calls : 0; return 1; @@ -3162,6 +3168,9 @@ smp_fetch_cpu_ns_avg(const struct arg *args, struct sample *smp, const char *kw, static int smp_fetch_cpu_ns_tot(const struct arg *args, struct sample *smp, const char *kw, void *private) { + if (!smp->strm) + return 0; + smp->data.type = SMP_T_SINT; smp->data.u.sint = smp->strm->task->cpu_time; return 1; @@ -3171,6 +3180,9 @@ smp_fetch_cpu_ns_tot(const struct arg *args, struct sample *smp, const char *kw, static int smp_fetch_lat_ns_avg(const struct arg *args, struct sample *smp, const char *kw, void *private) { + if (!smp->strm) + return 0; + smp->data.type = SMP_T_SINT; smp->data.u.sint = smp->strm->task->calls ? smp->strm->task->lat_time / smp->strm->task->calls : 0; return 1; @@ -3180,6 +3192,9 @@ smp_fetch_lat_ns_avg(const struct arg *args, struct sample *smp, const char *kw, static int smp_fetch_lat_ns_tot(const struct arg *args, struct sample *smp, const char *kw, void *private) { + if (!smp->strm) + return 0; + smp->data.type = SMP_T_SINT; smp->data.u.sint = smp->strm->task->lat_time; return 1; -- 1.7.10.4