From: Colin Ian King Date: Thu, 16 Jul 2020 14:38:56 +0000 (+0100) Subject: refperf: Avoid null pointer dereference when buf fails to allocate X-Git-Tag: v5.9.2~351 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7db67e4c4bfa21d29cfade3337217b94543eaa82;p=users%2Fdwmw2%2Flinux.git refperf: Avoid null pointer dereference when buf fails to allocate [ Upstream commit 58db5785b0d76be4582a32a7900acce88e691d36 ] 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 Signed-off-by: Paul E. McKenney Signed-off-by: Sasha Levin --- diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c index d9291f883b542..952595c678b37 100644 --- a/kernel/rcu/refscale.c +++ b/kernel/rcu/refscale.c @@ -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;