From: Daniel Mack Date: Fri, 9 Jan 2015 14:12:39 +0000 (+0100) Subject: message: simplify -EMSGSIZE test X-Git-Tag: upstream/0.20150129.081441utc~55 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e776f3ee18797658c25e04ae85358073e6baa49a;p=platform%2Fcore%2Fsystem%2Fkdbus-bus.git 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 --- 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;