From e38babcdf9d735d15a90d91f225d115bf9e97433 Mon Sep 17 00:00:00 2001
From: Florin Coras <fcoras@cisco.com>
Date: Thu, 3 Feb 2022 11:48:55 -0800
Subject: http: honor max seg len in ptr buffer

Type: fix

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I58ecd933f36c6622f4c6b373d2d94a48f9fc9eae
---
 src/plugins/http/http_buffer.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

(limited to 'src')

diff --git a/src/plugins/http/http_buffer.c b/src/plugins/http/http_buffer.c
index 5b4f5fc0300..0b031693682 100644
--- a/src/plugins/http/http_buffer.c
+++ b/src/plugins/http/http_buffer.c
@@ -158,6 +158,7 @@ buf_ptr_get_segs (http_buffer_t *hb, u32 max_len, u32 *n_segs)
   http_buffer_ptr_t *bf = (http_buffer_ptr_t *) &hb->data;
 
   *n_segs = 1;
+  bf->segs[1].len = clib_min (bf->segs[0].len, max_len);
 
   return &bf->segs[1];
 }
@@ -167,12 +168,14 @@ buf_ptr_drain (http_buffer_t *hb, u32 len)
 {
   http_buffer_ptr_t *bf = (http_buffer_ptr_t *) &hb->data;
 
+  ASSERT (bf->segs[0].len >= len);
+
   bf->segs[1].data += len;
-  bf->segs[1].len -= len;
+  bf->segs[0].len -= len;
 
   HTTP_DBG (1, "drained %u left %u", len, bf->segs[1].len);
 
-  if (!bf->segs[1].len)
+  if (!bf->segs[0].len)
     {
       svm_fifo_dequeue_drop (bf->f, sizeof (uword));
       return sizeof (uword);
@@ -186,8 +189,7 @@ buf_ptr_is_drained (http_buffer_t *hb)
 {
   http_buffer_ptr_t *bf = (http_buffer_ptr_t *) &hb->data;
 
-  ASSERT (bf->segs[1].len <= bf->segs[0].len);
-  return (bf->segs[1].len == 0);
+  return (bf->segs[0].len == 0);
 }
 
 const static http_buffer_vft_t buf_ptr_vft = {
-- 
cgit