[Openvpn-devel,2/5,v3] buffer_list_aggregate_separator(): update list size after aggregating

Message ID 1514541144-19407-1-git-send-email-steffan.karger@fox-it.com
State Accepted
Headers show
Series None | expand

Commit Message

Steffan Karger Dec. 28, 2017, 10:52 p.m. UTC
After aggregating a buffer_list, the size should be adjusted accordingly.

Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
---
v2: rebase on master
v3: add spaces around '-'

 src/openvpn/buffer.c                   |  1 +
 tests/unit_tests/openvpn/test_buffer.c | 15 +++++----------
 2 files changed, 6 insertions(+), 10 deletions(-)

Comments

Antonio Quartulli Dec. 28, 2017, 10:56 p.m. UTC | #1
Hi,

On 29/12/17 17:52, Steffan Karger wrote:
> After aggregating a buffer_list, the size should be adjusted accordingly.
> 
> Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>

Acked-by: Antonio Quartulli <a@unstable.cc>
Gert Doering Jan. 9, 2018, 5:26 a.m. UTC | #2
Your patch has been applied to the master and release/2.4 branch (bugfix).

commit 463afdf57c52891936b9a856e1030b7ebc55e75c (master)
commit 9abfb754a7dfa77ac90e7580d2250912fbdb45f6 (release/2.4)
Author: Steffan Karger
Date:   Fri Dec 29 10:52:24 2017 +0100

     buffer_list_aggregate_separator(): update list size after aggregating

     Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
     Acked-by: Antonio Quartulli <antonio@openvpn.net>
     Message-Id: <1514541144-19407-1-git-send-email-steffan.karger@fox-it.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg16103.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

Patch

diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index e601a31..28ce8ca 100644
--- a/src/openvpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ -1257,6 +1257,7 @@  buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max, const
                 e = next;
             }
             bl->head = f;
+            bl->size -= count - 1;
             f->next = more;
             if (!more)
             {
diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c
index b4625bb..bddb30a 100644
--- a/tests/unit_tests/openvpn/test_buffer.c
+++ b/tests/unit_tests/openvpn/test_buffer.c
@@ -138,8 +138,7 @@  test_buffer_list_aggregate_separator_two(void **state)
     /* Aggregate the first two elements */
     /* FIXME this exceeds the supplied max */
     buffer_list_aggregate_separator(ctx->one_two_three, 4, testsep);
-    /* FIXME size does not get adjusted after aggregating */
-    assert_int_equal(ctx->one_two_three->size, 3);
+    assert_int_equal(ctx->one_two_three->size, 2);
     struct buffer *buf = buffer_list_peek(ctx->one_two_three);
     assert_buf_equals_str(buf, teststr1 testsep teststr2 testsep);
 }
@@ -151,8 +150,7 @@  test_buffer_list_aggregate_separator_all(void **state)
 
     /* Aggregate all */
     buffer_list_aggregate_separator(ctx->one_two_three, 1<<16, testsep);
-    /* FIXME size does not get adjusted after aggregating */
-    assert_int_equal(ctx->one_two_three->size, 3);
+    assert_int_equal(ctx->one_two_three->size, 1);
     struct buffer *buf = buffer_list_peek(ctx->one_two_three);
     assert_buf_equals_str(buf,
                           teststr1 testsep teststr2 testsep teststr3 testsep);
@@ -165,8 +163,7 @@  test_buffer_list_aggregate_separator_nosep(void **state)
 
     /* Aggregate all */
     buffer_list_aggregate_separator(ctx->one_two_three, 1<<16, testnosep);
-    /* FIXME size does not get adjusted after aggregating */
-    assert_int_equal(ctx->one_two_three->size, 3);
+    assert_int_equal(ctx->one_two_three->size, 1);
     struct buffer *buf = buffer_list_peek(ctx->one_two_three);
     assert_buf_equals_str(buf, teststr1 teststr2 teststr3);
 }
@@ -179,8 +176,7 @@  test_buffer_list_aggregate_separator_zerolen(void **state)
 
     /* Aggregate all */
     buffer_list_aggregate_separator(bl_zerolen, 1<<16, testnosep);
-    /* FIXME size does not get adjusted after aggregating */
-    assert_int_equal(bl_zerolen->size, 2);
+    assert_int_equal(bl_zerolen->size, 1);
     struct buffer *buf = buffer_list_peek(bl_zerolen);
     assert_buf_equals_str(buf, "");
 }
@@ -193,8 +189,7 @@  test_buffer_list_aggregate_separator_emptybuffers(void **state)
 
     /* Aggregate all */
     buffer_list_aggregate_separator(bl_emptybuffers, 1<<16, testnosep);
-    /* FIXME size does not get adjusted after aggregating */
-    assert_int_equal(bl_emptybuffers->size, 2);
+    assert_int_equal(bl_emptybuffers->size, 1);
     struct buffer *buf = buffer_list_peek(bl_emptybuffers);
     assert_int_equal(BLEN(buf), 0);
 }