From e776f3ee18797658c25e04ae85358073e6baa49a Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Fri, 9 Jan 2015 15:12:39 +0100 Subject: [PATCH] message: simplify -EMSGSIZE test Simplify the code a bit and check for pool size overflows after we did the modulo operation. Signed-off-by: Daniel Mack --- message.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/message.c b/message.c index a1d396c..305bad8 100644 --- a/message.c +++ b/message.c @@ -255,10 +255,6 @@ static int kdbus_msg_scan_items(struct kdbus_kmsg *kmsg, 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; @@ -273,6 +269,9 @@ static int kdbus_msg_scan_items(struct kdbus_kmsg *kmsg, 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; -- 2.34.1