From: Anatoly Burakov Date: Tue, 17 Apr 2018 15:44:07 +0000 (+0100) Subject: fbarray: fix potential null-dereference X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=f9a4f1b4623a8f6673a15670c314be18c0efe623;p=dpdk.git fbarray: fix potential null-dereference We get pointer to mask before we check if fbarray is NULL. Fix by moving getting mask pointer to until after NULL check. Coverity issue: 272579 Fixes: c44d09811b40 ("eal: add shared indexed file-backed array") Signed-off-by: Anatoly Burakov Acked-by: Adrien Mazarguil --- diff --git a/lib/librte_eal/common/eal_common_fbarray.c b/lib/librte_eal/common/eal_common_fbarray.c index 2263f4c078..d17611b57f 100644 --- a/lib/librte_eal/common/eal_common_fbarray.c +++ b/lib/librte_eal/common/eal_common_fbarray.c @@ -355,7 +355,7 @@ find_contig(const struct rte_fbarray *arr, unsigned int start, bool used) static int set_used(struct rte_fbarray *arr, unsigned int idx, bool used) { - struct used_mask *msk = get_used_mask(arr->data, arr->elt_sz, arr->len); + struct used_mask *msk; uint64_t msk_bit = 1ULL << MASK_LEN_TO_MOD(idx); unsigned int msk_idx = MASK_LEN_TO_IDX(idx); bool already_used; @@ -365,6 +365,7 @@ set_used(struct rte_fbarray *arr, unsigned int idx, bool used) rte_errno = EINVAL; return -1; } + msk = get_used_mask(arr->data, arr->elt_sz, arr->len); ret = 0; /* prevent array from changing under us */