| 1075 | } |
| 1076 | |
| 1077 | const unsigned char * |
| 1078 | nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds, |
| 1079 | bool *isbep, size_t *leftp) |
| 1080 | { |
| 1081 | struct nvlist_header nvlhdr; |
| 1082 | int inarrayf; |
| 1083 | |
| 1084 | if (*leftp < sizeof(nvlhdr)) |
| 1085 | goto fail; |
| 1086 | |
| 1087 | memcpy(&nvlhdr, ptr, sizeof(nvlhdr)); |
| 1088 | |
| 1089 | if (!nvlist_check_header(&nvlhdr)) |
| 1090 | goto fail; |
| 1091 | |
| 1092 | if (nvlhdr.nvlh_size != *leftp - sizeof(nvlhdr)) |
| 1093 | goto fail; |
| 1094 | |
| 1095 | /* |
| 1096 | * nvlh_descriptors might be smaller than nfds in embedded nvlists. |
| 1097 | */ |
| 1098 | if (nvlhdr.nvlh_descriptors > nfds) |
| 1099 | goto fail; |
| 1100 | |
| 1101 | if ((nvlhdr.nvlh_flags & ~NV_FLAG_ALL_MASK) != 0) |
| 1102 | goto fail; |
| 1103 | |
| 1104 | inarrayf = (nvl->nvl_flags & NV_FLAG_IN_ARRAY); |
| 1105 | nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK) | inarrayf; |
| 1106 | |
| 1107 | ptr += sizeof(nvlhdr); |
| 1108 | if (isbep != NULL) |
| 1109 | *isbep = (((int)nvlhdr.nvlh_flags & NV_FLAG_BIG_ENDIAN) != 0); |
| 1110 | *leftp -= sizeof(nvlhdr); |
| 1111 | |
| 1112 | return (ptr); |
| 1113 | fail: |
| 1114 | ERRNO_SET(EINVAL); |
| 1115 | return (NULL); |
| 1116 | } |
| 1117 | |
| 1118 | static nvlist_t * |
| 1119 | nvlist_xunpack(const void *buf, size_t size, const int *fds, size_t nfds, |
no test coverage detected