zstreamdump dumps core printing truncated nvlist

This change prevents zstreamdump from crashing when trying to print
invalid nvlist data (DRR_BEGIN record) from a truncated send stream.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #7917
This commit is contained in:
LOLi 2018-09-18 18:43:09 +02:00 committed by Brian Behlendorf
parent 81155b296d
commit e0b7ff46c9

View File

@ -384,10 +384,12 @@ main(int argc, char *argv[])
if (ferror(send_stream))
perror("fread");
err = nvlist_unpack(buf, sz, &nv, 0);
if (err)
if (err) {
perror(strerror(err));
nvlist_print(stdout, nv);
nvlist_free(nv);
} else {
nvlist_print(stdout, nv);
nvlist_free(nv);
}
}
break;