| 1021 | |
| 1022 | #ifndef _KERNEL |
| 1023 | const unsigned char * |
| 1024 | nvpair_unpack_descriptor_array(bool isbe, nvpair_t *nvp, |
| 1025 | const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds) |
| 1026 | { |
| 1027 | int64_t idx; |
| 1028 | size_t size; |
| 1029 | unsigned int ii; |
| 1030 | int *array; |
| 1031 | |
| 1032 | PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR_ARRAY); |
| 1033 | |
| 1034 | size = sizeof(idx) * nvp->nvp_nitems; |
| 1035 | if (nvp->nvp_datasize != size || *leftp < size || |
| 1036 | nvp->nvp_nitems == 0 || size < nvp->nvp_nitems) { |
| 1037 | ERRNO_SET(EINVAL); |
| 1038 | return (NULL); |
| 1039 | } |
| 1040 | |
| 1041 | array = (int *)nv_malloc(size); |
| 1042 | if (array == NULL) |
| 1043 | return (NULL); |
| 1044 | |
| 1045 | for (ii = 0; ii < nvp->nvp_nitems; ii++) { |
| 1046 | if (isbe) |
| 1047 | idx = be64dec(ptr); |
| 1048 | else |
| 1049 | idx = le64dec(ptr); |
| 1050 | |
| 1051 | if (idx < 0) { |
| 1052 | ERRNO_SET(EINVAL); |
| 1053 | nv_free(array); |
| 1054 | return (NULL); |
| 1055 | } |
| 1056 | |
| 1057 | if ((size_t)idx >= nfds) { |
| 1058 | ERRNO_SET(EINVAL); |
| 1059 | nv_free(array); |
| 1060 | return (NULL); |
| 1061 | } |
| 1062 | |
| 1063 | array[ii] = (uint64_t)fds[idx]; |
| 1064 | |
| 1065 | ptr += sizeof(idx); |
| 1066 | *leftp -= sizeof(idx); |
| 1067 | } |
| 1068 | |
| 1069 | nvp->nvp_data = (uint64_t)(uintptr_t)array; |
| 1070 | |
| 1071 | return (ptr); |
| 1072 | } |
| 1073 | #endif |
| 1074 | |
| 1075 | const unsigned char * |
no test coverage detected