aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2025-03-17 20:24:20 +1100
committerStefano Brivio <sbrivio@redhat.com>2025-03-20 20:33:20 +0100
commit961aa6a0eb7fce956a34f8ccd883bfe12392d3d3 (patch)
treec3e0f15b2eee7dbf3c2c013a52973f78c46289d5
parent37d9f374d9f0c47c092f80a5d85d4505ae4a9af7 (diff)
downloadpasst-961aa6a0eb7fce956a34f8ccd883bfe12392d3d3.tar
passt-961aa6a0eb7fce956a34f8ccd883bfe12392d3d3.tar.gz
passt-961aa6a0eb7fce956a34f8ccd883bfe12392d3d3.tar.bz2
passt-961aa6a0eb7fce956a34f8ccd883bfe12392d3d3.tar.lz
passt-961aa6a0eb7fce956a34f8ccd883bfe12392d3d3.tar.xz
passt-961aa6a0eb7fce956a34f8ccd883bfe12392d3d3.tar.zst
passt-961aa6a0eb7fce956a34f8ccd883bfe12392d3d3.zip
packet: Move checks against PACKET_MAX_LEN to packet_check_range()
Both the callers of packet_check_range() separately verify that the given length does not exceed PACKET_MAX_LEN. Fold that check into packet_check_range() instead. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--packet.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/packet.c b/packet.c
index fdc4be7..7cbe95d 100644
--- a/packet.c
+++ b/packet.c
@@ -35,6 +35,12 @@
static int packet_check_range(const struct pool *p, const char *ptr, size_t len,
const char *func, int line)
{
+ if (len > PACKET_MAX_LEN) {
+ trace("packet range length %zu (max %zu), %s:%i",
+ len, PACKET_MAX_LEN, func, line);
+ return -1;
+ }
+
if (p->buf_size == 0) {
int ret;
@@ -100,11 +106,6 @@ void packet_add_do(struct pool *p, size_t len, const char *start,
if (packet_check_range(p, start, len, func, line))
return;
- if (len > PACKET_MAX_LEN) {
- trace("add packet length %zu, %s:%i", len, func, line);
- return;
- }
-
p->pkt[idx].iov_base = (void *)start;
p->pkt[idx].iov_len = len;
@@ -136,14 +137,6 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset,
return NULL;
}
- if (len > PACKET_MAX_LEN) {
- if (func) {
- trace("packet data length %zu, %s:%i",
- len, func, line);
- }
- return NULL;
- }
-
if (offset > p->pkt[idx].iov_len ||
len > (p->pkt[idx].iov_len - offset)) {
if (func) {