From: Craig Small Date: Sat, 14 May 2016 12:32:35 +0000 (+1000) Subject: library: slab sort derefence after check X-Git-Tag: v4.0.0~906 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4f6b8c9c60e730858dfd1cc086f39ea783ae00c9;p=procps-ng 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 --- 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;