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 <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14044
This commit is contained in:
Richard Yao 2022-10-14 22:55:48 -04:00 committed by Tony Hutter
parent a5f17a94d3
commit bbec0e60a8
1 changed files with 4 additions and 2 deletions

View File

@ -988,8 +988,10 @@ zap_lookup_impl(zap_t *zap, const char *name,
} else { } else {
*(uint64_t *)buf = *(uint64_t *)buf =
MZE_PHYS(zap, mze)->mze_value; MZE_PHYS(zap, mze)->mze_value;
(void) strlcpy(realname, if (realname != NULL)
MZE_PHYS(zap, mze)->mze_name, rn_len); (void) strlcpy(realname,
MZE_PHYS(zap, mze)->mze_name,
rn_len);
if (ncp) { if (ncp) {
*ncp = mzap_normalization_conflict(zap, *ncp = mzap_normalization_conflict(zap,
zn, mze); zn, mze);