Make the code consistent by always using 'fail' label.
Submitted by: pjd@ and oshogbo@ MFC after: 1 month Sponsored by: Wheel Systems
This commit is contained in:
parent
1dacabe1ab
commit
a3c485d38d
@ -1067,24 +1067,24 @@ nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
|
|||||||
int inarrayf;
|
int inarrayf;
|
||||||
|
|
||||||
if (*leftp < sizeof(nvlhdr))
|
if (*leftp < sizeof(nvlhdr))
|
||||||
goto failed;
|
goto fail;
|
||||||
|
|
||||||
memcpy(&nvlhdr, ptr, sizeof(nvlhdr));
|
memcpy(&nvlhdr, ptr, sizeof(nvlhdr));
|
||||||
|
|
||||||
if (!nvlist_check_header(&nvlhdr))
|
if (!nvlist_check_header(&nvlhdr))
|
||||||
goto failed;
|
goto fail;
|
||||||
|
|
||||||
if (nvlhdr.nvlh_size != *leftp - sizeof(nvlhdr))
|
if (nvlhdr.nvlh_size != *leftp - sizeof(nvlhdr))
|
||||||
goto failed;
|
goto fail;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* nvlh_descriptors might be smaller than nfds in embedded nvlists.
|
* nvlh_descriptors might be smaller than nfds in embedded nvlists.
|
||||||
*/
|
*/
|
||||||
if (nvlhdr.nvlh_descriptors > nfds)
|
if (nvlhdr.nvlh_descriptors > nfds)
|
||||||
goto failed;
|
goto fail;
|
||||||
|
|
||||||
if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0)
|
if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0)
|
||||||
goto failed;
|
goto fail;
|
||||||
|
|
||||||
inarrayf = (nvl->nvl_flags & NV_FLAG_IN_ARRAY);
|
inarrayf = (nvl->nvl_flags & NV_FLAG_IN_ARRAY);
|
||||||
nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK) | inarrayf;
|
nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK) | inarrayf;
|
||||||
@ -1095,7 +1095,7 @@ nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
|
|||||||
*leftp -= sizeof(nvlhdr);
|
*leftp -= sizeof(nvlhdr);
|
||||||
|
|
||||||
return (ptr);
|
return (ptr);
|
||||||
failed:
|
fail:
|
||||||
ERRNO_SET(EINVAL);
|
ERRNO_SET(EINVAL);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -1118,20 +1118,20 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
|
|||||||
tmpnvl = array = NULL;
|
tmpnvl = array = NULL;
|
||||||
nvl = retnvl = nvlist_create(0);
|
nvl = retnvl = nvlist_create(0);
|
||||||
if (nvl == NULL)
|
if (nvl == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
|
|
||||||
ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
|
ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
if (nvl->nvl_flags != flags) {
|
if (nvl->nvl_flags != flags) {
|
||||||
ERRNO_SET(EILSEQ);
|
ERRNO_SET(EILSEQ);
|
||||||
goto failed;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (left > 0) {
|
while (left > 0) {
|
||||||
ptr = nvpair_unpack(isbe, ptr, &left, &nvp);
|
ptr = nvpair_unpack(isbe, ptr, &left, &nvp);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
switch (nvpair_type(nvp)) {
|
switch (nvpair_type(nvp)) {
|
||||||
case NV_TYPE_NULL:
|
case NV_TYPE_NULL:
|
||||||
ptr = nvpair_unpack_null(isbe, nvp, ptr, &left);
|
ptr = nvpair_unpack_null(isbe, nvp, ptr, &left);
|
||||||
@ -1149,7 +1149,7 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
|
|||||||
ptr = nvpair_unpack_nvlist(isbe, nvp, ptr, &left, nfds,
|
ptr = nvpair_unpack_nvlist(isbe, nvp, ptr, &left, nfds,
|
||||||
&tmpnvl);
|
&tmpnvl);
|
||||||
if (tmpnvl == NULL || ptr == NULL)
|
if (tmpnvl == NULL || ptr == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
nvlist_set_parent(tmpnvl, nvp);
|
nvlist_set_parent(tmpnvl, nvp);
|
||||||
break;
|
break;
|
||||||
#ifndef _KERNEL
|
#ifndef _KERNEL
|
||||||
@ -1167,14 +1167,14 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
|
|||||||
break;
|
break;
|
||||||
case NV_TYPE_NVLIST_UP:
|
case NV_TYPE_NVLIST_UP:
|
||||||
if (nvl->nvl_parent == NULL)
|
if (nvl->nvl_parent == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
nvl = nvpair_nvlist(nvl->nvl_parent);
|
nvl = nvpair_nvlist(nvl->nvl_parent);
|
||||||
nvpair_free_structure(nvp);
|
nvpair_free_structure(nvp);
|
||||||
continue;
|
continue;
|
||||||
case NV_TYPE_NVLIST_ARRAY_NEXT:
|
case NV_TYPE_NVLIST_ARRAY_NEXT:
|
||||||
if (nvl->nvl_array_next == NULL) {
|
if (nvl->nvl_array_next == NULL) {
|
||||||
if (nvl->nvl_parent == NULL)
|
if (nvl->nvl_parent == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
nvl = nvpair_nvlist(nvl->nvl_parent);
|
nvl = nvpair_nvlist(nvl->nvl_parent);
|
||||||
} else {
|
} else {
|
||||||
nvl = __DECONST(nvlist_t *,
|
nvl = __DECONST(nvlist_t *,
|
||||||
@ -1182,7 +1182,7 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
|
|||||||
ptr = nvlist_unpack_header(nvl, ptr, nfds,
|
ptr = nvlist_unpack_header(nvl, ptr, nfds,
|
||||||
&isbe, &left);
|
&isbe, &left);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
}
|
}
|
||||||
nvpair_free_structure(nvp);
|
nvpair_free_structure(nvp);
|
||||||
continue;
|
continue;
|
||||||
@ -1199,7 +1199,7 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
|
|||||||
ptr = nvpair_unpack_nvlist_array(isbe, nvp, ptr, &left,
|
ptr = nvpair_unpack_nvlist_array(isbe, nvp, ptr, &left,
|
||||||
&array);
|
&array);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
PJDLOG_ASSERT(array != NULL);
|
PJDLOG_ASSERT(array != NULL);
|
||||||
tmpnvl = array;
|
tmpnvl = array;
|
||||||
do {
|
do {
|
||||||
@ -1214,9 +1214,9 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
|
|||||||
PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
|
PJDLOG_ABORT("Invalid type (%d).", nvpair_type(nvp));
|
||||||
}
|
}
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
if (!nvlist_move_nvpair(nvl, nvp))
|
if (!nvlist_move_nvpair(nvl, nvp))
|
||||||
goto failed;
|
goto fail;
|
||||||
if (tmpnvl != NULL) {
|
if (tmpnvl != NULL) {
|
||||||
nvl = tmpnvl;
|
nvl = tmpnvl;
|
||||||
tmpnvl = NULL;
|
tmpnvl = NULL;
|
||||||
@ -1224,7 +1224,7 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (retnvl);
|
return (retnvl);
|
||||||
failed:
|
fail:
|
||||||
nvlist_destroy(retnvl);
|
nvlist_destroy(retnvl);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
@ -614,7 +614,7 @@ nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
|
|||||||
struct nvpair_header nvphdr;
|
struct nvpair_header nvphdr;
|
||||||
|
|
||||||
if (*leftp < sizeof(nvphdr))
|
if (*leftp < sizeof(nvphdr))
|
||||||
goto failed;
|
goto fail;
|
||||||
|
|
||||||
memcpy(&nvphdr, ptr, sizeof(nvphdr));
|
memcpy(&nvphdr, ptr, sizeof(nvphdr));
|
||||||
ptr += sizeof(nvphdr);
|
ptr += sizeof(nvphdr);
|
||||||
@ -622,12 +622,12 @@ nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
|
|||||||
|
|
||||||
#if NV_TYPE_FIRST > 0
|
#if NV_TYPE_FIRST > 0
|
||||||
if (nvphdr.nvph_type < NV_TYPE_FIRST)
|
if (nvphdr.nvph_type < NV_TYPE_FIRST)
|
||||||
goto failed;
|
goto fail;
|
||||||
#endif
|
#endif
|
||||||
if (nvphdr.nvph_type > NV_TYPE_LAST &&
|
if (nvphdr.nvph_type > NV_TYPE_LAST &&
|
||||||
nvphdr.nvph_type != NV_TYPE_NVLIST_UP &&
|
nvphdr.nvph_type != NV_TYPE_NVLIST_UP &&
|
||||||
nvphdr.nvph_type != NV_TYPE_NVLIST_ARRAY_NEXT) {
|
nvphdr.nvph_type != NV_TYPE_NVLIST_ARRAY_NEXT) {
|
||||||
goto failed;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BYTE_ORDER == BIG_ENDIAN
|
#if BYTE_ORDER == BIG_ENDIAN
|
||||||
@ -643,14 +643,14 @@ nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (nvphdr.nvph_namesize > NV_NAME_MAX)
|
if (nvphdr.nvph_namesize > NV_NAME_MAX)
|
||||||
goto failed;
|
goto fail;
|
||||||
if (*leftp < nvphdr.nvph_namesize)
|
if (*leftp < nvphdr.nvph_namesize)
|
||||||
goto failed;
|
goto fail;
|
||||||
if (nvphdr.nvph_namesize < 1)
|
if (nvphdr.nvph_namesize < 1)
|
||||||
goto failed;
|
goto fail;
|
||||||
if (strnlen((const char *)ptr, nvphdr.nvph_namesize) !=
|
if (strnlen((const char *)ptr, nvphdr.nvph_namesize) !=
|
||||||
(size_t)(nvphdr.nvph_namesize - 1)) {
|
(size_t)(nvphdr.nvph_namesize - 1)) {
|
||||||
goto failed;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(nvp->nvp_name, ptr, nvphdr.nvph_namesize);
|
memcpy(nvp->nvp_name, ptr, nvphdr.nvph_namesize);
|
||||||
@ -658,7 +658,7 @@ nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
|
|||||||
*leftp -= nvphdr.nvph_namesize;
|
*leftp -= nvphdr.nvph_namesize;
|
||||||
|
|
||||||
if (*leftp < nvphdr.nvph_datasize)
|
if (*leftp < nvphdr.nvph_datasize)
|
||||||
goto failed;
|
goto fail;
|
||||||
|
|
||||||
nvp->nvp_type = nvphdr.nvph_type;
|
nvp->nvp_type = nvphdr.nvph_type;
|
||||||
nvp->nvp_data = 0;
|
nvp->nvp_data = 0;
|
||||||
@ -666,7 +666,7 @@ nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
|
|||||||
nvp->nvp_nitems = nvphdr.nvph_nitems;
|
nvp->nvp_nitems = nvphdr.nvph_nitems;
|
||||||
|
|
||||||
return (ptr);
|
return (ptr);
|
||||||
failed:
|
fail:
|
||||||
ERRNO_SET(EINVAL);
|
ERRNO_SET(EINVAL);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -1108,10 +1108,10 @@ nvpair_unpack(bool isbe, const unsigned char *ptr, size_t *leftp,
|
|||||||
|
|
||||||
ptr = nvpair_unpack_header(isbe, nvp, ptr, leftp);
|
ptr = nvpair_unpack_header(isbe, nvp, ptr, leftp);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
tmp = nv_realloc(nvp, sizeof(*nvp) + strlen(nvp->nvp_name) + 1);
|
tmp = nv_realloc(nvp, sizeof(*nvp) + strlen(nvp->nvp_name) + 1);
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
goto failed;
|
goto fail;
|
||||||
nvp = tmp;
|
nvp = tmp;
|
||||||
|
|
||||||
/* Update nvp_name after realloc(). */
|
/* Update nvp_name after realloc(). */
|
||||||
@ -1120,7 +1120,7 @@ nvpair_unpack(bool isbe, const unsigned char *ptr, size_t *leftp,
|
|||||||
nvp->nvp_magic = NVPAIR_MAGIC;
|
nvp->nvp_magic = NVPAIR_MAGIC;
|
||||||
*nvpp = nvp;
|
*nvpp = nvp;
|
||||||
return (ptr);
|
return (ptr);
|
||||||
failed:
|
fail:
|
||||||
nv_free(nvp);
|
nv_free(nvp);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user