From bbec0e60a8e75e9f63a6a415a86054b42ef6d675 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Fri, 14 Oct 2022 22:55:48 -0400 Subject: [PATCH] Fix NULL pointer passed to strlcpy from zap_lookup_impl() Clang's static analyzer pointed out that whenever zap_lookup_by_dnode() is called, we have the following stack where strlcpy() is passed a NULL pointer for realname from zap_lookup_by_dnode(): strlcpy() zap_lookup_impl() zap_lookup_norm_by_dnode() zap_lookup_by_dnode() Reviewed-by: Brian Behlendorf Signed-off-by: Richard Yao Closes #14044 --- module/zfs/zap_micro.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/module/zfs/zap_micro.c b/module/zfs/zap_micro.c index 1f32e44505..516d46ac7f 100644 --- a/module/zfs/zap_micro.c +++ b/module/zfs/zap_micro.c @@ -988,8 +988,10 @@ zap_lookup_impl(zap_t *zap, const char *name, } else { *(uint64_t *)buf = MZE_PHYS(zap, mze)->mze_value; - (void) strlcpy(realname, - MZE_PHYS(zap, mze)->mze_name, rn_len); + if (realname != NULL) + (void) strlcpy(realname, + MZE_PHYS(zap, mze)->mze_name, + rn_len); if (ncp) { *ncp = mzap_normalization_conflict(zap, zn, mze);