From: Florin Coras Date: Thu, 8 May 2025 04:03:59 +0000 (-0400) Subject: tcp: fix coverity discard bytes warning X-Git-Tag: v25.10-rc0~27 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F32%2F42932%2F2;p=vpp.git tcp: fix coverity discard bytes warning Type: fix Change-Id: Id832d1e240e42b8ce76f243c14ca67e724a4ef34 Signed-off-by: Florin Coras --- diff --git a/src/vnet/tcp/tcp_input.c b/src/vnet/tcp/tcp_input.c index 404afb18764..3abfc9512a7 100644 --- a/src/vnet/tcp/tcp_input.c +++ b/src/vnet/tcp/tcp_input.c @@ -1179,18 +1179,21 @@ tcp_buffer_discard_bytes (vlib_buffer_t * b, u32 n_bytes_to_drop) /* Handle multi-buffer segments */ if (n_bytes_to_drop > b->current_length) { - if (!(b->flags & VLIB_BUFFER_NEXT_PRESENT)) + if (!(b->flags & VLIB_BUFFER_NEXT_PRESENT) || + (first + b->total_length_not_including_first_buffer < + n_bytes_to_drop)) return -1; + b->total_length_not_including_first_buffer -= n_bytes_to_drop - first; do { discard = clib_min (n_bytes_to_drop, b->current_length); vlib_buffer_advance (b, discard); b = vlib_get_buffer (vm, b->next_buffer); n_bytes_to_drop -= discard; + if (!b && n_bytes_to_drop) + return -1; } while (n_bytes_to_drop); - if (n_bytes_to_drop > first) - b->total_length_not_including_first_buffer -= n_bytes_to_drop - first; } else vlib_buffer_advance (b, n_bytes_to_drop);