On 10/11/2017 05:09 AM, Daniel P. Berrange wrote: > Instead of requiring use of another Buffer, pass a struct iovec > into qio_channel_websock_encode, which gives callers more > flexibility in how they process data. > > Signed-off-by: Daniel P. Berrange <[email protected]>
> +static void qio_channel_websock_encode(QIOChannelWebsock *ioc,
> + uint8_t opcode,
> + const struct iovec *iov,
> + size_t niov,
> + size_t size)
> {
> size_t header_size;
> + size_t i;
> union {
> char buf[QIO_CHANNEL_WEBSOCK_HEADER_LEN_64_BIT];
> QIOChannelWebsockHeader ws;
Is it worth adding assert(size <= iov_size(iov, niov)) near the top,
> + trace_qio_channel_websock_encode(ioc, opcode, header_size, size);
> + buffer_reserve(&ioc->encoutput, header_size + size);
> + buffer_append(&ioc->encoutput, header.buf, header_size);
> + for (i = 0; i < niov && size != 0; i++) {
> + size_t want = iov[i].iov_len;
> + if (want > size) {
> + want = size;
> + }
> + buffer_append(&ioc->encoutput, iov[i].iov_base, want);
> + size -= want;
> + }
so we don't have to worry about a huge size causing us to buffer_reserve
far too much space?
Doesn't affect my R-b, though.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
