Simplify the code a bit and check for pool size overflows after we did
the modulo operation.
Signed-off-by: Daniel Mack <daniel@zonque.org>
return -EMSGSIZE;
if (vec_size + size > KDBUS_MSG_MAX_PAYLOAD_VEC_SIZE)
return -EMSGSIZE;
- if (ptr && kmsg->pool_size + size < kmsg->pool_size)
- return -EMSGSIZE;
- if (!ptr && kmsg->pool_size + size % 8 < kmsg->pool_size)
- return -EMSGSIZE;
d->type = KDBUS_MSG_DATA_VEC;
d->size = size;
iov->iov_len = size % 8;
}
+ if (kmsg->pool_size + iov->iov_len < kmsg->pool_size)
+ return -EMSGSIZE;
+
kmsg->pool_size += iov->iov_len;
++kmsg->iov_count;
++res->vec_count;