diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-09-06 21:49:39 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-09-06 13:56:46 +0200 |
commit | a33ecafbd921a681ef65b66624625a1beac43c50 (patch) | |
tree | 4be31a6a22efb039c08d47bd2dff5a7dc48171e9 | |
parent | d2a1dc744b10d3e5253149a2520db9967f9f20d5 (diff) | |
download | passt-a33ecafbd921a681ef65b66624625a1beac43c50.tar passt-a33ecafbd921a681ef65b66624625a1beac43c50.tar.gz passt-a33ecafbd921a681ef65b66624625a1beac43c50.tar.bz2 passt-a33ecafbd921a681ef65b66624625a1beac43c50.tar.lz passt-a33ecafbd921a681ef65b66624625a1beac43c50.tar.xz passt-a33ecafbd921a681ef65b66624625a1beac43c50.tar.zst passt-a33ecafbd921a681ef65b66624625a1beac43c50.zip |
tap: Don't risk truncating frames on full buffer in tap_pasta_input()
tap_pasta_input() keeps reading frames from the tap device until the
buffer is full. However, this has an ugly edge case, when we get close
to buffer full, we will provide just the remaining space as a read()
buffer. If this is shorter than the next frame to read, the tap device
will truncate the frame and discard the remainder.
Adjust the code to make sure we always have room for a maximum size frame.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r-- | tap.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -1076,8 +1076,8 @@ static void tap_pasta_input(struct ctx *c, const struct timespec *now) tap_flush_pools(); - for (n = 0; n < (ssize_t)TAP_BUF_BYTES; n += len) { - len = read(c->fd_tap, pkt_buf + n, TAP_BUF_BYTES - n); + for (n = 0; n <= (ssize_t)TAP_BUF_BYTES - ETH_MAX_MTU; n += len) { + len = read(c->fd_tap, pkt_buf + n, ETH_MAX_MTU); if (len == 0) { die("EOF on tap device, exiting"); |