HomeFreeBSD

Handle possible null pointers from malloc/strdup/strndup()

Description

Handle possible null pointers from malloc/strdup/strndup()

GCC 12.1.1_p20220625's static analyzer caught these.

Of the two in the btree test, one had previously been caught by Coverity
and Smatch, but GCC flagged it as a false positive. Upon examining how
other test cases handle this, the solution was changed from
ASSERT3P(node, !=, NULL); to using perror() to be consistent with
the fixes to the other fixes done to the ZTS code.

That approach was also used in ZED since I did not see a better way of
handling this there. Also, upon inspection, additional unchecked
pointers from malloc()/calloc()/strdup() were found in ZED, so those
were handled too.

In other parts of the code, the existing methods to avoid issues from
memory allocators returning NULL were used, such as using
umem_alloc(size, UMEM_NOFAIL) or returning ENOMEM.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #13979

Details

Provenance
Richard Yao <richard.yao@alumni.stonybrook.edu>Authored on Oct 7 2022, 12:18 AM
GitHub <noreply@github.com>Committed on Oct 7 2022, 12:18 AM
Parents
rG2ba240f3583e: PAM: Fix unchecked return value from zfs_key_config_load()
Branches
Unknown
Tags
Unknown

Event Timeline

GitHub <noreply@github.com> committed rG72c99dc95961: Handle possible null pointers from malloc/strdup/strndup() (authored by Richard Yao <richard.yao@alumni.stonybrook.edu>).Oct 7 2022, 12:18 AM