From 4d9bb5514c5ab1b025384db3f3c42eca550ff944 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Tue, 7 Feb 2023 02:38:45 -0500 Subject: [PATCH] Suppress static analyzer warnings in zio_checksum_error_impl() Clang's static analyzer informs us of multiple NULL pointer dereferences involving zio_checksum_error_impl(). The first is a NULL pointer dereference if bp is NULL and ci->ci_flags & ZCHECKSUM_FLAG_EMBEDDED is false, but bp is NULL implies that ci->ci_flags & ZCHECKSUM_FLAG_EMBEDDED is true, so we add an IMPLY() statement to suppress the report. The second and third are identical, and are duplicated because while the NULL pointer dereference occurs in zio_checksum_gang_verifier(), it is called by zio_checksum_error_impl() and there is a report for each of the two functions. The reports state that when bp is NULL, ci->ci_flags & ZCHECKSUM_FLAG_EMBEDDED is true and checksum is not ZIO_CHECKSUM_LABEL, we also have a NULL pointer dereference. bp is NULL should imply that checksum == ZIO_CHECKSUM_LABEL, so we add an IMPLY() statement to suppress the second report. The two reports are functionally identical. A fourth variation of this was also reported by Coverity. It occurs when checksum == ZIO_CHECKSUM_ZILOG2. Reviewed-by: Brian Behlendorf Reviewed-by: Brian Atkinson Signed-off-by: Richard Yao Reported-by: Coverity (CID-1524672) Closes #14470 --- module/zfs/zio_checksum.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/zfs/zio_checksum.c b/module/zfs/zio_checksum.c index 37cd35bc84..3743eaa532 100644 --- a/module/zfs/zio_checksum.c +++ b/module/zfs/zio_checksum.c @@ -423,6 +423,9 @@ zio_checksum_error_impl(spa_t *spa, const blkptr_t *bp, zio_checksum_template_init(checksum, spa); + IMPLY(bp == NULL, ci->ci_flags & ZCHECKSUM_FLAG_EMBEDDED); + IMPLY(bp == NULL, checksum == ZIO_CHECKSUM_LABEL); + if (ci->ci_flags & ZCHECKSUM_FLAG_EMBEDDED) { zio_cksum_t verifier; size_t eck_offset;