Handle empty nvlists correctly.
Submitted by: Mariusz Zaborski <oshogbo@FreeBSD.org>
This commit is contained in:
parent
83723416a6
commit
d9dde7dc21
@ -356,7 +356,8 @@ nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level)
|
||||
void
|
||||
nvlist_dump(const nvlist_t *nvl, int fd)
|
||||
{
|
||||
nvpair_t *nvp;
|
||||
const nvlist_t *tmpnvl;
|
||||
nvpair_t *nvp, *tmpnvp;
|
||||
int level;
|
||||
|
||||
level = 0;
|
||||
@ -386,13 +387,17 @@ nvlist_dump(const nvlist_t *nvl, int fd)
|
||||
break;
|
||||
case NV_TYPE_NVLIST:
|
||||
dprintf(fd, "\n");
|
||||
nvl = nvpair_get_nvlist(nvp);
|
||||
if (nvlist_dump_error_check(nvl, fd, level + 1)) {
|
||||
nvl = nvlist_get_parent(nvl, (void **)&nvp);
|
||||
tmpnvl = nvpair_get_nvlist(nvp);
|
||||
if (nvlist_dump_error_check(tmpnvl, fd, level + 1))
|
||||
break;
|
||||
tmpnvp = nvlist_first_nvpair(tmpnvl);
|
||||
if (tmpnvp != NULL) {
|
||||
nvl = tmpnvl;
|
||||
nvp = tmpnvp;
|
||||
level++;
|
||||
continue;
|
||||
}
|
||||
level++;
|
||||
continue;
|
||||
break;
|
||||
case NV_TYPE_DESCRIPTOR:
|
||||
dprintf(fd, " %d\n", nvpair_get_descriptor(nvp));
|
||||
break;
|
||||
@ -436,7 +441,8 @@ nvlist_fdump(const nvlist_t *nvl, FILE *fp)
|
||||
size_t
|
||||
nvlist_size(const nvlist_t *nvl)
|
||||
{
|
||||
const nvpair_t *nvp;
|
||||
const nvlist_t *tmpnvl;
|
||||
const nvpair_t *nvp, *tmpnvp;
|
||||
size_t size;
|
||||
|
||||
NVLIST_ASSERT(nvl);
|
||||
@ -450,10 +456,14 @@ nvlist_size(const nvlist_t *nvl)
|
||||
if (nvpair_type(nvp) == NV_TYPE_NVLIST) {
|
||||
size += sizeof(struct nvlist_header);
|
||||
size += nvpair_header_size() + 1;
|
||||
nvl = nvpair_get_nvlist(nvp);
|
||||
PJDLOG_ASSERT(nvl->nvl_error == 0);
|
||||
nvp = nvlist_first_nvpair(nvl);
|
||||
continue;
|
||||
tmpnvl = nvpair_get_nvlist(nvp);
|
||||
PJDLOG_ASSERT(tmpnvl->nvl_error == 0);
|
||||
tmpnvp = nvlist_first_nvpair(tmpnvl);
|
||||
if (tmpnvp != NULL) {
|
||||
nvl = tmpnvl;
|
||||
nvp = tmpnvp;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
size += nvpair_size(nvp);
|
||||
}
|
||||
@ -575,7 +585,8 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
|
||||
{
|
||||
unsigned char *buf, *ptr;
|
||||
size_t left, size;
|
||||
nvpair_t *nvp;
|
||||
const nvlist_t *tmpnvl;
|
||||
nvpair_t *nvp, *tmpnvp;
|
||||
|
||||
NVLIST_ASSERT(nvl);
|
||||
|
||||
@ -618,10 +629,18 @@ nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
|
||||
ptr = nvpair_pack_string(nvp, ptr, &left);
|
||||
break;
|
||||
case NV_TYPE_NVLIST:
|
||||
nvl = nvpair_get_nvlist(nvp);
|
||||
nvp = nvlist_first_nvpair(nvl);
|
||||
ptr = nvlist_pack_header(nvl, ptr, &left);
|
||||
continue;
|
||||
tmpnvl = nvpair_get_nvlist(nvp);
|
||||
ptr = nvlist_pack_header(tmpnvl, ptr, &left);
|
||||
if (ptr == NULL)
|
||||
goto out;
|
||||
tmpnvp = nvlist_first_nvpair(tmpnvl);
|
||||
if (tmpnvp != NULL) {
|
||||
nvl = tmpnvl;
|
||||
nvp = tmpnvp;
|
||||
continue;
|
||||
}
|
||||
ptr = nvpair_pack_nvlist_up(ptr, &left);
|
||||
break;
|
||||
case NV_TYPE_DESCRIPTOR:
|
||||
ptr = nvpair_pack_descriptor(nvp, ptr, fdidxp, &left);
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user