Both packet_add_do() and packet_get_do() have a check on the given length, essentially sanity checking it before validating that it's in an expected memory region. This can be folded into packet_check_range() which performs similar checks for both functions. Signed-off-by: David Gibson <david(a)gibson.dropbear.id.au> --- packet.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packet.c b/packet.c index 24f12448..9e0e6555 100644 --- a/packet.c +++ b/packet.c @@ -37,6 +37,10 @@ static void packet_check_range(const struct pool *p, const char *ptr, size_t len, const char *func, int line) { + ASSERT_WITH_MSG(len <= PACKET_MAX_LEN, + "packet_check_range length %zu (max %zu), %s:%i", + len, PACKET_MAX_LEN, func, line); + if (p->buf_size == 0) { vu_packet_check_range((void *)p->buf, ptr, len, func, line); return; @@ -72,10 +76,6 @@ void packet_add_do(struct pool *p, size_t len, const char *start, packet_check_range(p, start, len, func, line); - ASSERT_WITH_MSG(len <= PACKET_MAX_LEN, - "add packet length %zu (max %zu), %s:%i", - len, PACKET_MAX_LEN, func, line); - p->pkt[idx].iov_base = (void *)start; p->pkt[idx].iov_len = len; @@ -102,9 +102,6 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, ASSERT_WITH_MSG(idx < p->size && idx < p->count, "packet %zu from pool size: %zu, count: %zu, %s:%i", idx, p->size, p->count, func, line); - ASSERT_WITH_MSG(len <= PACKET_MAX_LEN, - "packet range length %zu (max %zu), %s:%i", - len, PACKET_MAX_LEN, func, line); if (len + offset > p->pkt[idx].iov_len) { trace("data length %zu, offset %zu from length %zu, %s:%i", -- 2.47.1