Skip to contentSkip to conversation

Change in openvpn[master]: test_buffer: Add test for buf_null_terminate

Openvpn-devel In review flichtenheld (Code Review) 2 participants 6 messages Mar 18 – Apr 7 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1773842036000.I01683153a68e1809a4d7ab455eb346f53780e219@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1580?usp=email

to review the following change.

Change subject: test_buffer: Add test for buf_null_terminate
......................................................................

test_buffer: Add test for buf_null_terminate

Change-Id I01683153a68e1809a4d7ab455eb346f53780e219

---
M tests/unit_tests/openvpn/test_buffer.c

1 file changed, 27 insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/80/1580/1

tests/unit_tests/openvpn/test_buffer.c +27 -0
index 5f43e0d..326de40 100644
@@ -460,6 +460,32 @@
     gc_free(&gc);
 }
 
+void
+test_buffer_null_terminate(void **state)
+{
+    struct gc_arena gc = gc_new();
+
+    struct buffer buf = alloc_buf_gc(5, &gc);
+    const char test1[] = "1234";
+    const char test2[] = "12345";
+    assert_true(buf_write(&buf, test1, sizeof(test1)));
+    assert_string_equal(BSTR(&buf), "1234");
+    buf_null_terminate(&buf);
+    assert_string_equal(BSTR(&buf), "1234");
+
+    assert_true(buf_inc_len(&buf, -1));
+    assert_true(buf_write_u8(&buf, '5'));
+    assert_memory_equal(BPTR(&buf), test2, strlen(test2));
+    buf_null_terminate(&buf);
+    assert_string_equal(BSTR(&buf), "1234");
+
+    struct buffer buf2;
+    CLEAR(buf2);
+    buf_null_terminate(&buf2);
+
+    gc_free(&gc);
+}
+
 /* for building long texts */
 #define A_TIMES_256 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO"
 
@@ -540,6 +566,7 @@
         cmocka_unit_test(test_snprintf),
         cmocka_unit_test(test_checked_snprintf),
         cmocka_unit_test(test_buffer_chomp),
+        cmocka_unit_test(test_buffer_null_terminate),
         cmocka_unit_test(test_buffer_parse)
     };
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1580?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I01683153a68e1809a4d7ab455eb346f53780e219
Gerrit-Change-Number: 1580
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1580?usp=email )

Change subject: test_buffer: Add test for buf_null_terminate
......................................................................

Patch Set 1: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1580?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I01683153a68e1809a4d7ab455eb346f53780e219
Gerrit-Change-Number: 1580
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 07 Apr 2026 09:50:31 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#3 lore raw

PATCH 1/1 test_buffer: Add test for buf_null_terminate

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

Change-Id I01683153a68e1809a4d7ab455eb346f53780e219

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1580
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1580
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

tests/unit_tests/openvpn/test_buffer.c +27 -0
index 5f43e0d..326de40 100644
@@ -460,6 +460,32 @@
     gc_free(&gc);
 }
 
+void
+test_buffer_null_terminate(void **state)
+{
+    struct gc_arena gc = gc_new();
+
+    struct buffer buf = alloc_buf_gc(5, &gc);
+    const char test1[] = "1234";
+    const char test2[] = "12345";
+    assert_true(buf_write(&buf, test1, sizeof(test1)));
+    assert_string_equal(BSTR(&buf), "1234");
+    buf_null_terminate(&buf);
+    assert_string_equal(BSTR(&buf), "1234");
+
+    assert_true(buf_inc_len(&buf, -1));
+    assert_true(buf_write_u8(&buf, '5'));
+    assert_memory_equal(BPTR(&buf), test2, strlen(test2));
+    buf_null_terminate(&buf);
+    assert_string_equal(BSTR(&buf), "1234");
+
+    struct buffer buf2;
+    CLEAR(buf2);
+    buf_null_terminate(&buf2);
+
+    gc_free(&gc);
+}
+
 /* for building long texts */
 #define A_TIMES_256 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO"
 
@@ -540,6 +566,7 @@
         cmocka_unit_test(test_snprintf),
         cmocka_unit_test(test_checked_snprintf),
         cmocka_unit_test(test_buffer_chomp),
+        cmocka_unit_test(test_buffer_null_terminate),
         cmocka_unit_test(test_buffer_parse)
     };
 
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: test_buffer: Add test for buf_null_terminate

This is easy - it adds a test instance to one of the pre-existing unit tests, the test works

[ RUN ] test_buffer_null_terminate
[ OK ] test_buffer_null_terminate

.. and it does so on all the instances in buildbot. In it goes...

Your patch has been applied to the master branch.

commit 798884d6df200c95b2c22de31860f3e35be617f7

Author: Frank Lichtenheld
Date:   Tue Apr 7 11:50:38 2026 +0200
     test_buffer: Add test for buf_null_terminate

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1580
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg36532.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#2) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1580?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: test_buffer: Add test for buf_null_terminate
......................................................................

test_buffer: Add test for buf_null_terminate

Change-Id I01683153a68e1809a4d7ab455eb346f53780e219

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1580
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36532.html

---
M tests/unit_tests/openvpn/test_buffer.c

1 file changed, 27 insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/80/1580/2

tests/unit_tests/openvpn/test_buffer.c +27 -0
index 5f43e0d..326de40 100644
@@ -460,6 +460,32 @@
     gc_free(&gc);
 }
 
+void
+test_buffer_null_terminate(void **state)
+{
+    struct gc_arena gc = gc_new();
+
+    struct buffer buf = alloc_buf_gc(5, &gc);
+    const char test1[] = "1234";
+    const char test2[] = "12345";
+    assert_true(buf_write(&buf, test1, sizeof(test1)));
+    assert_string_equal(BSTR(&buf), "1234");
+    buf_null_terminate(&buf);
+    assert_string_equal(BSTR(&buf), "1234");
+
+    assert_true(buf_inc_len(&buf, -1));
+    assert_true(buf_write_u8(&buf, '5'));
+    assert_memory_equal(BPTR(&buf), test2, strlen(test2));
+    buf_null_terminate(&buf);
+    assert_string_equal(BSTR(&buf), "1234");
+
+    struct buffer buf2;
+    CLEAR(buf2);
+    buf_null_terminate(&buf2);
+
+    gc_free(&gc);
+}
+
 /* for building long texts */
 #define A_TIMES_256 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO"
 
@@ -540,6 +566,7 @@
         cmocka_unit_test(test_snprintf),
         cmocka_unit_test(test_checked_snprintf),
         cmocka_unit_test(test_buffer_chomp),
+        cmocka_unit_test(test_buffer_null_terminate),
         cmocka_unit_test(test_buffer_parse)
     };
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1580?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I01683153a68e1809a4d7ab455eb346f53780e219
Gerrit-Change-Number: 1580
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1580?usp=email )

Change subject: test_buffer: Add test for buf_null_terminate
......................................................................

test_buffer: Add test for buf_null_terminate

Change-Id I01683153a68e1809a4d7ab455eb346f53780e219

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1580
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg36532.html

---
M tests/unit_tests/openvpn/test_buffer.c

1 file changed, 27 insertions(+), 0 deletions(-)
tests/unit_tests/openvpn/test_buffer.c +27 -0
index 5f43e0d..326de40 100644
@@ -460,6 +460,32 @@
     gc_free(&gc);
 }
 
+void
+test_buffer_null_terminate(void **state)
+{
+    struct gc_arena gc = gc_new();
+
+    struct buffer buf = alloc_buf_gc(5, &gc);
+    const char test1[] = "1234";
+    const char test2[] = "12345";
+    assert_true(buf_write(&buf, test1, sizeof(test1)));
+    assert_string_equal(BSTR(&buf), "1234");
+    buf_null_terminate(&buf);
+    assert_string_equal(BSTR(&buf), "1234");
+
+    assert_true(buf_inc_len(&buf, -1));
+    assert_true(buf_write_u8(&buf, '5'));
+    assert_memory_equal(BPTR(&buf), test2, strlen(test2));
+    buf_null_terminate(&buf);
+    assert_string_equal(BSTR(&buf), "1234");
+
+    struct buffer buf2;
+    CLEAR(buf2);
+    buf_null_terminate(&buf2);
+
+    gc_free(&gc);
+}
+
 /* for building long texts */
 #define A_TIMES_256 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO"
 
@@ -540,6 +566,7 @@
         cmocka_unit_test(test_snprintf),
         cmocka_unit_test(test_checked_snprintf),
         cmocka_unit_test(test_buffer_chomp),
+        cmocka_unit_test(test_buffer_null_terminate),
         cmocka_unit_test(test_buffer_parse)
     };
 

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1580?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I01683153a68e1809a4d7ab455eb346f53780e219
Gerrit-Change-Number: 1580
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>