]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: sample: make the CPU and latency sample fetches check for a stream
authorWilly Tarreau <w@1wt.eu>
Wed, 29 Apr 2020 09:59:02 +0000 (11:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 29 Apr 2020 09:59:02 +0000 (11:59 +0200)
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.

src/sample.c

index c26882d1a51b13f76ce85854bc046c81c2d70d7b..8bdbbe458dfd9e30d635787a6568eaed9edc995d 100644 (file)
@@ -3222,6 +3222,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;
@@ -3231,6 +3234,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;
@@ -3240,6 +3246,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;
@@ -3249,6 +3258,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;
@@ -3258,6 +3270,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;