message: simplify -EMSGSIZE test
authorDaniel Mack <daniel@zonque.org>
Fri, 9 Jan 2015 14:12:39 +0000 (15:12 +0100)
committerDaniel Mack <daniel@zonque.org>
Fri, 9 Jan 2015 14:12:39 +0000 (15:12 +0100)
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>
message.c

index a1d396c5409af4aeba650212baed3ab431c40941..305bad8b5e5b0e5b727898db2ca7a8c6837c8a51 100644 (file)
--- 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;