tcp: fix coverity discard bytes warning 32/42932/2
authorFlorin Coras <[email protected]>
Thu, 8 May 2025 04:03:59 +0000 (00:03 -0400)
committerFlorin Coras <[email protected]>
Thu, 8 May 2025 04:16:03 +0000 (04:16 +0000)
Type: fix

Change-Id: Id832d1e240e42b8ce76f243c14ca67e724a4ef34
Signed-off-by: Florin Coras <[email protected]>
src/vnet/tcp/tcp_input.c

index 404afb1..3abfc95 100644 (file)
@@ -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);