Skip to content

Commit

Permalink
Fix possible NULL pointer dereference in nvlist_lookup_nvpair_ei_sep()
Browse files Browse the repository at this point in the history
Clang's static analyzer complains about a possible NULL pointer
dereference in nvlist_lookup_nvpair_ei_sep() because it unconditionally
dereferences a pointer initialized by `nvpair_value_nvlist_array()`
under the assumption that `nvpair_value_nvlist_array()` will always
initialize the pointer without checking to see if an error was returned
to indicate otherwise. This itself is improper error handling, so we fix
it. However, fixing it to properly respond to errors is not enough to
avoid a NULL pointer dereference, since we can receive NULL when the
array is empty, so we also add a NULL check.

Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes openzfs#14612
  • Loading branch information
ryao authored and behlendorf committed Mar 14, 2023
1 parent 47b9940 commit 27ff18c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions module/nvpair/nvpair.c
Original file line number Diff line number Diff line change
Expand Up @@ -2057,8 +2057,11 @@ nvlist_lookup_nvpair_ei_sep(nvlist_t *nvl, const char *name, const char sep,
nvl = EMBEDDED_NVL(nvp);
break;
} else if (nvpair_type(nvp) == DATA_TYPE_NVLIST_ARRAY) {
(void) nvpair_value_nvlist_array(nvp,
&nva, (uint_t *)&n);
if (nvpair_value_nvlist_array(nvp,
&nva, (uint_t *)&n) != 0)
goto fail;
if (nva == NULL)
goto fail;
if ((n < 0) || (idx >= n))
goto fail;
nvl = nva[idx];
Expand Down

0 comments on commit 27ff18c

Please sign in to comment.