From edd685ad6f7f8aac58f9c59fb26217883a153c8c Mon Sep 17 00:00:00 2001 From: WHR Date: Tue, 12 Apr 2022 14:42:44 +0800 Subject: [PATCH] Fix zpool_history_unpack unconditionally returning ENOMEM on nvlist_unpack failure Signed-off-by: WHR --- lib/libzutil/zutil_pool.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libzutil/zutil_pool.c b/lib/libzutil/zutil_pool.c index 734650f3cffc..2428d9c8552e 100644 --- a/lib/libzutil/zutil_pool.c +++ b/lib/libzutil/zutil_pool.c @@ -109,6 +109,7 @@ zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover, nvlist_t *nv; int i; void *tmp; + int err; while (bytes_read > sizeof (reclen)) { @@ -120,8 +121,9 @@ zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover, break; /* unpack record */ - if (nvlist_unpack(buf + sizeof (reclen), reclen, &nv, 0) != 0) - return (ENOMEM); + err = nvlist_unpack(buf + sizeof (reclen), reclen, &nv, 0); + if (err != 0) + return (err); bytes_read -= sizeof (reclen) + reclen; buf += sizeof (reclen) + reclen;