| 6217 | } |
| 6218 | if (ret.host_len != 0 || ret.port != 0) { |
| 6219 | if (errlen) snprintf(err, errlen, "invalid upstream route final destination"); |
| 6220 | return false; |
| 6221 | } |
| 6222 | p += ret.host_len; |
| 6223 | remaining -= ret.host_len; |
| 6224 | if (remaining != 0) { |
| 6225 | if (errlen) snprintf(err, errlen, "route payload has trailing bytes"); |
| 6226 | return false; |
| 6227 | } |
| 6228 | return true; |
| 6229 | } |
| 6230 | |
| 6231 | static int dist_send_work_frame( |
| 6232 | int fd, |
| 6233 | const ds4_dist_work_fixed *work, |
| 6234 | const int *tokens, |
| 6235 | const float *input_hc, |
| 6236 | const void *route_blob) { |
| 6237 | if (!work || !tokens || work->n_tokens == 0) return -1; |
| 6238 | const uint64_t token_bytes = (uint64_t)work->n_tokens * sizeof(uint32_t); |
| 6239 | if (token_bytes > UINT32_MAX || work->token_bytes != (uint32_t)token_bytes) return -1; |
| 6240 | if (work->input_hc_bytes != 0 && !input_hc) return -1; |
| 6241 | if (work->route_bytes != 0 && !route_blob) return -1; |
| 6242 | uint64_t input_hc_values = 0; |
| 6243 | if (work->input_hc_bytes != 0 && |
| 6244 | !dist_activation_values_from_wire_bytes(work->input_hc_bits, |
| 6245 | work->input_hc_bytes, |
| 6246 | &input_hc_values)) |
| 6247 | return -1; |
| 6248 | const uint64_t frame_bytes = sizeof(ds4_dist_work_fixed) + |
| 6249 | (uint64_t)work->token_bytes + |
| 6250 | work->input_hc_bytes + |
| 6251 | work->route_bytes; |
| 6252 | if (frame_bytes > UINT32_MAX) return -1; |
| 6253 | |
| 6254 | ds4_dist_work_fixed wire = *work; |
| 6255 | dist_work_to_wire(&wire); |
| 6256 | if (dist_write_frame_header(fd, DS4_DIST_MSG_WORK, (uint32_t)frame_bytes) != 0) return -1; |
| 6257 | if (dist_write_full(fd, &wire, sizeof(wire)) != 0) return -1; |
| 6258 | for (uint32_t i = 0; i < work->n_tokens; i++) { |
| 6259 | uint32_t t = htonl((uint32_t)tokens[i]); |
| 6260 | if (dist_write_full(fd, &t, sizeof(t)) != 0) return -1; |
| 6261 | } |
no test coverage detected