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:
Mariusz Zaborski 2017-09-21 10:06:00 +00:00
parent 1dacabe1ab
commit a3c485d38d
2 changed files with 30 additions and 30 deletions

View File

@ -1067,24 +1067,24 @@ nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
int inarrayf;
if (*leftp < sizeof(nvlhdr))
goto failed;
goto fail;
memcpy(&nvlhdr, ptr, sizeof(nvlhdr));
if (!nvlist_check_header(&nvlhdr))
goto failed;
goto fail;
if (nvlhdr.nvlh_size != *leftp - sizeof(nvlhdr))
goto failed;
goto fail;
/*
* nvlh_descriptors might be smaller than nfds in embedded nvlists.
*/
if (nvlhdr.nvlh_descriptors > nfds)
goto failed;
goto fail;
if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0)
goto failed;
goto fail;
inarrayf = (nvl->nvl_flags & NV_FLAG_IN_ARRAY);
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);
return (ptr);
failed:
fail:
ERRNO_SET(EINVAL);
return (NULL);
}
@ -1118,20 +1118,20 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
tmpnvl = array = NULL;
nvl = retnvl = nvlist_create(0);
if (nvl == NULL)
goto failed;
goto fail;
ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
if (ptr == NULL)
goto failed;
goto fail;
if (nvl->nvl_flags != flags) {
ERRNO_SET(EILSEQ);
goto failed;
goto fail;
}
while (left > 0) {
ptr = nvpair_unpack(isbe, ptr, &left, &nvp);
if (ptr == NULL)
goto failed;
goto fail;
switch (nvpair_type(nvp)) {
case NV_TYPE_NULL:
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,
&tmpnvl);
if (tmpnvl == NULL || ptr == NULL)
goto failed;
goto fail;
nvlist_set_parent(tmpnvl, nvp);
break;
#ifndef _KERNEL
@ -1167,14 +1167,14 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
break;
case NV_TYPE_NVLIST_UP:
if (nvl->nvl_parent == NULL)
goto failed;
goto fail;
nvl = nvpair_nvlist(nvl->nvl_parent);
nvpair_free_structure(nvp);
continue;
case NV_TYPE_NVLIST_ARRAY_NEXT:
if (nvl->nvl_array_next == NULL) {
if (nvl->nvl_parent == NULL)
goto failed;
goto fail;
nvl = nvpair_nvlist(nvl->nvl_parent);
} else {
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,
&isbe, &left);
if (ptr == NULL)
goto failed;
goto fail;
}
nvpair_free_structure(nvp);
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,
&array);
if (ptr == NULL)
goto failed;
goto fail;
PJDLOG_ASSERT(array != NULL);
tmpnvl = array;
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));
}
if (ptr == NULL)
goto failed;
goto fail;
if (!nvlist_move_nvpair(nvl, nvp))
goto failed;
goto fail;
if (tmpnvl != NULL) {
nvl = tmpnvl;
tmpnvl = NULL;
@ -1224,7 +1224,7 @@ nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds,
}
return (retnvl);
failed:
fail:
nvlist_destroy(retnvl);
return (NULL);
}

View File

@ -614,7 +614,7 @@ nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
struct nvpair_header nvphdr;
if (*leftp < sizeof(nvphdr))
goto failed;
goto fail;
memcpy(&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 (nvphdr.nvph_type < NV_TYPE_FIRST)
goto failed;
goto fail;
#endif
if (nvphdr.nvph_type > NV_TYPE_LAST &&
nvphdr.nvph_type != NV_TYPE_NVLIST_UP &&
nvphdr.nvph_type != NV_TYPE_NVLIST_ARRAY_NEXT) {
goto failed;
goto fail;
}
#if BYTE_ORDER == BIG_ENDIAN
@ -643,14 +643,14 @@ nvpair_unpack_header(bool isbe, nvpair_t *nvp, const unsigned char *ptr,
#endif
if (nvphdr.nvph_namesize > NV_NAME_MAX)
goto failed;
goto fail;
if (*leftp < nvphdr.nvph_namesize)
goto failed;
goto fail;
if (nvphdr.nvph_namesize < 1)
goto failed;
goto fail;
if (strnlen((const char *)ptr, nvphdr.nvph_namesize) !=
(size_t)(nvphdr.nvph_namesize - 1)) {
goto failed;
goto fail;
}
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;
if (*leftp < nvphdr.nvph_datasize)
goto failed;
goto fail;
nvp->nvp_type = nvphdr.nvph_type;
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;
return (ptr);
failed:
fail:
ERRNO_SET(EINVAL);
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);
if (ptr == NULL)
goto failed;
goto fail;
tmp = nv_realloc(nvp, sizeof(*nvp) + strlen(nvp->nvp_name) + 1);
if (tmp == NULL)
goto failed;
goto fail;
nvp = tmp;
/* 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;
*nvpp = nvp;
return (ptr);
failed:
fail:
nv_free(nvp);
return (NULL);
}