From 4f6b8c9c60e730858dfd1cc086f39ea783ae00c9 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sat, 14 May 2016 22:32:35 +1000 Subject: [PATCH] library: slab sort derefence after check procps_slabnode_stacks_sort() would check if stacks was NULL *after* the pointer was derefenced in the initialisation of the variable p. p is now assigned after the check. References: Coverity #99160 --- proc/slab.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proc/slab.c b/proc/slab.c index a3c5dca6..b72fcb5d 100644 --- a/proc/slab.c +++ b/proc/slab.c @@ -836,11 +836,12 @@ PROCPS_EXPORT struct slabnode_stack **procps_slabnode_stacks_sort ( enum slabnode_item sort) { #define QSORT_r int (*)(const void *, const void *, void *) - struct slab_result *p = stacks[0]->head; + struct slab_result *p; int offset = 0;; if (info == NULL || stacks == NULL) return NULL; + if (sort < 0 || sort > PROCPS_SLABNODE_noop) return NULL; if (numstacked > info->stacked->depth) @@ -851,6 +852,7 @@ PROCPS_EXPORT struct slabnode_stack **procps_slabnode_stacks_sort ( if (numstacked > info->stacked->inuse) numstacked = info->stacked->inuse; + p = stacks[0]->head; for (;;) { if (p->item == sort) break; -- 2.40.0