refperf: Avoid null pointer dereference when buf fails to allocate
authorColin Ian King <colin.king@canonical.com>
Thu, 16 Jul 2020 14:38:56 +0000 (15:38 +0100)
committerPaul E. McKenney <paulmck@kernel.org>
Tue, 25 Aug 2020 01:45:35 +0000 (18:45 -0700)
Currently in the unlikely event that buf fails to be allocated it
is dereferenced a few times.  Use the errexit flag to determine if
buf should be written to to avoid the null pointer dereferences.

Addresses-Coverity: ("Dereference after null check")
Fixes: f518f154ecef ("refperf: Dynamically allocate experiment-summary output buffer")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/refscale.c

index d9291f8..952595c 100644 (file)
@@ -546,9 +546,11 @@ static int main_func(void *arg)
        // Print the average of all experiments
        SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n");
 
-       buf[0] = 0;
-       strcat(buf, "\n");
-       strcat(buf, "Runs\tTime(ns)\n");
+       if (!errexit) {
+               buf[0] = 0;
+               strcat(buf, "\n");
+               strcat(buf, "Runs\tTime(ns)\n");
+       }
 
        for (exp = 0; exp < nruns; exp++) {
                u64 avg;