From: "cron2 (Code Review)" Date: Mon, 13 Oct 2025 16:02:45 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <96f4c809a942a436f376e6834d62cc6355c76304-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="sy5b8+Jcg20="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: test_dhcp: Start a dhcp helper functions UT List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --sy5b8+Jcg20= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#5) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1267?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: test_dhcp: Start a dhcp helper functions UT ...................................................................... test_dhcp: Start a dhcp helper functions UT Use extra define to allow testing code only used on Windows but not actually dependent on Windows. Change-Id: I08e50030b1b692d351509f541e5c0b03b5170615 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1267 Message-Id: <20251013154758.21695-1-gert@...1296...> URL: https://sourceforge.net/p/openvpn/mailman/message/59246199/ Signed-off-by: Gert Doering --- M CMakeLists.txt M src/openvpn/dhcp.c M src/openvpn/dhcp.h M src/openvpn/tun.h M tests/unit_tests/openvpn/Makefile.am M tests/unit_tests/openvpn/mock_msg.h A tests/unit_tests/openvpn/test_dhcp.c 7 files changed, 155 insertions(+), 4 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/67/1267/5 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e0b46e..b773dcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -658,6 +658,7 @@ "test_auth_token" "test_buffer" "test_crypto" + "test_dhcp" "test_misc" "test_ncp" "test_options_parse" @@ -910,6 +911,11 @@ ) endif () + target_compile_definitions(test_dhcp PRIVATE DHCP_UNIT_TEST) + target_sources(test_dhcp PRIVATE + tests/unit_tests/openvpn/mock_get_random.c + ) + if (TARGET test_networking) target_link_options(test_networking PRIVATE -Wl,--wrap=3Dparse_lin= e) target_compile_options(test_networking PRIVATE -UNDEBUG) diff --git a/src/openvpn/dhcp.c b/src/openvpn/dhcp.c index 56f03f2..0893ec7 100644 --- a/src/openvpn/dhcp.c +++ b/src/openvpn/dhcp.c @@ -186,7 +186,7 @@ return 0; } -#if defined(_WIN32) +#if defined(_WIN32) || defined(DHCP_UNIT_TEST) #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push diff --git a/src/openvpn/dhcp.h b/src/openvpn/dhcp.h index 3fcd2b6..2ad31a6 100644 --- a/src/openvpn/dhcp.h +++ b/src/openvpn/dhcp.h @@ -93,7 +93,7 @@ in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf); -#if defined(_WIN32) +#if defined(_WIN32) || defined(DHCP_UNIT_TEST) #include "tun.h" bool build_dhcp_options_string(struct buffer *buf, const struct tuntap_opt= ions *o); diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index 6562c22..741798d 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -59,7 +59,7 @@ #define DCO_WIN_REFERENCE_STRING "ovpn-dco" #endif -#if defined(_WIN32) || defined(TARGET_ANDROID) +#if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNIT_TEST) #define TUN_ADAPTER_INDEX_INVALID ((DWORD)-1) diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/unit_tests/openvp= n/Makefile.am index 50f4a11..17aa0ce 100644 --- a/tests/unit_tests/openvpn/Makefile.am +++ b/tests/unit_tests/openvpn/Makefile.am @@ -6,7 +6,7 @@ AM_TESTS_ENVIRONMENT =3D export LSAN_OPTIONS=3Dsuppressions=3D$(srcdir)/in= put/leak_suppr.txt; -test_binaries =3D argv_testdriver buffer_testdriver crypto_testdriver pack= et_id_testdriver auth_token_testdriver \ +test_binaries =3D argv_testdriver buffer_testdriver crypto_testdriver dhcp= _testdriver packet_id_testdriver auth_token_testdriver \ ncp_testdriver misc_testdriver options_parse_testdriver pkt_testdriver ss= l_testdriver \ user_pass_testdriver push_update_msg_testdriver provider_testdriver socke= t_testdriver @@ -72,6 +72,15 @@ $(top_srcdir)/src/openvpn/win32-util.c \ $(top_srcdir)/src/openvpn/mss.c +dhcp_testdriver_CFLAGS =3D -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/sr= c/compat @TEST_CFLAGS@ -DDHCP_UNIT_TEST +dhcp_testdriver_LDFLAGS =3D @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn +dhcp_testdriver_SOURCES =3D test_dhcp.c \ + mock_msg.c mock_msg.h test_common.h \ + mock_get_random.c \ + $(top_srcdir)/src/openvpn/platform.c \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/win32-util.c + ssl_testdriver_CFLAGS =3D \ -I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/op= envpn \ @TEST_CFLAGS@ diff --git a/tests/unit_tests/openvpn/mock_msg.h b/tests/unit_tests/openvpn= /mock_msg.h index c6321dc..62afde5 100644 --- a/tests/unit_tests/openvpn/mock_msg.h +++ b/tests/unit_tests/openvpn/mock_msg.h @@ -23,6 +23,8 @@ #ifndef MOCK_MSG_H #define MOCK_MSG_H +#include "error.h" + /** * Mock debug level defaults to 0, which gives clean(-ish) test reports. = Call * this function from your test driver to increase debug output when you diff --git a/tests/unit_tests/openvpn/test_dhcp.c b/tests/unit_tests/openvp= n/test_dhcp.c new file mode 100644 index 0000000..729ca58 --- /dev/null +++ b/tests/unit_tests/openvpn/test_dhcp.c @@ -0,0 +1,134 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2025 OpenVPN Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "syshead.h" + +#include +#include +#include +#include +#include +#include + +#include "test_common.h" +#include "mock_msg.h" + +#include "dhcp.c" + +uint16_t +ip_checksum(const sa_family_t af, const uint8_t *payload, const int len_pa= yload, + const uint8_t *src_addr, const uint8_t *dest_addr, const int p= roto) +{ + return 0; +} +const char * +print_in_addr_t(in_addr_t addr, unsigned int flags, struct gc_arena *gc) +{ + return "dummy"; +} + +static void +test_write_dhcp_search_str(void **state) +{ + struct gc_arena gc =3D gc_new(); + struct buffer out_buf =3D alloc_buf_gc(512, &gc); + struct buffer clear_buf =3D alloc_buf_gc(512, &gc); + buf_clear(&clear_buf); + bool error =3D false; + +#define LONGDOMAIN "a-reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa= aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa= aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa= aaaaaaaaaaaaaaaaally-long-domain" + const char *search_list[] =3D { + "openvpn.net", + "openvpn.org", + LONGDOMAIN, + "subdomain." LONGDOMAIN ".top123", /* maximum length */ + "subdomain-" LONGDOMAIN "-top123", /* maximum length */ + "subdomain." LONGDOMAIN ".top1234", /* too long */ + "sub..tld", /* invalid */ + }; + const unsigned char output_1[28] =3D "\x77\x1a\x07openvpn\x03net\x00\x= 07openvpn\x03org"; + buf_clear(&out_buf); + write_dhcp_search_str(&out_buf, DHCP_DOMAIN_SEARCH, search_list, 2, &e= rror); + assert_memory_equal(BPTR(&out_buf), output_1, sizeof(output_1)); + assert_false(error); + + /* buf too small */ + struct buffer small_buf =3D alloc_buf_gc(sizeof(output_1) - 1, &gc); + buf_clear(&small_buf); + write_dhcp_search_str(&small_buf, DHCP_DOMAIN_SEARCH, search_list, 2, = &error); + assert_memory_equal(BPTR(&small_buf), BPTR(&clear_buf), buf_forward_ca= pacity_total(&small_buf)); + assert_true(error); + error =3D false; + + const unsigned char output_2[0xEC + 3 + 1] =3D "\x77\xEE\xEC" LONGDOMA= IN; + buf_clear(&out_buf); + write_dhcp_search_str(&out_buf, DHCP_DOMAIN_SEARCH, search_list + 2, 1= , &error); + assert_memory_equal(BPTR(&out_buf), output_2, sizeof(output_2)); + assert_false(error); + + const unsigned char output_3[0xEC + 3 + 10 + 7 + 1] =3D "\x77\xFF\x09s= ubdomain\xEC" LONGDOMAIN "\x06top123"; + buf_clear(&out_buf); + write_dhcp_search_str(&out_buf, DHCP_DOMAIN_SEARCH, search_list + 3, 1= , &error); + assert_memory_equal(BPTR(&out_buf), output_3, sizeof(output_3)); + assert_false(error); + + const unsigned char output_4[0xEC + 3 + 10 + 7 + 1] =3D "\x77\xFF\xFDs= ubdomain-" LONGDOMAIN "-top123"; + buf_clear(&out_buf); + write_dhcp_search_str(&out_buf, DHCP_DOMAIN_SEARCH, search_list + 4, 1= , &error); + assert_memory_equal(BPTR(&out_buf), output_4, sizeof(output_4)); + assert_false(error); + + buf_clear(&out_buf); + write_dhcp_search_str(&out_buf, DHCP_DOMAIN_SEARCH, search_list + 5, 1= , &error); + assert_memory_equal(BPTR(&out_buf), BPTR(&clear_buf), buf_forward_capa= city_total(&clear_buf)); + assert_true(error); + error =3D false; + + buf_clear(&out_buf); + write_dhcp_search_str(&out_buf, DHCP_DOMAIN_SEARCH, search_list, 3, &e= rror); + assert_memory_equal(BPTR(&out_buf), BPTR(&clear_buf), buf_forward_capa= city_total(&clear_buf)); + assert_true(error); + error =3D false; + + /* FIXME: should probably throw an error instead adding that \x00 ? */ + const char output_5[12] =3D "\x77\x0a\x03sub\x00\x03tld"; + buf_clear(&out_buf); + write_dhcp_search_str(&out_buf, DHCP_DOMAIN_SEARCH, search_list + 6, 1= , &error); + assert_memory_equal(BPTR(&out_buf), output_5, sizeof(output_5)); + assert_false(error); + + gc_free(&gc); +} + +int +main(void) +{ + const struct CMUnitTest tests[] =3D { + cmocka_unit_test(test_write_dhcp_search_str), + }; + + return cmocka_run_group_tests_name("dhcp", tests, NULL, NULL); +} -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1267?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I08e50030b1b692d351509f541e5c0b03b5170615 Gerrit-Change-Number: 1267 Gerrit-PatchSet: 5 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --sy5b8+Jcg20= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #5 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by cron2

test_dhcp: Start a dhcp helper func=
tions UT

Use extra define to allow testing code only
used on Wind= ows but not actually dependent
on Windows.

Change-Id: I08e50030b1= b692d351509f541e5c0b03b5170615
Signed-off-by: Frank Lichtenheld <fran= k@...2641...>
Acked-by: Gert Doering <gert@...1296...>
Gerri= t URL: https://gerrit.openvpn.net/c/openvpn/+/1267
Message-Id: <20251= 013154758.21695-1-gert@...1296...>
URL: https://sourceforge.net/p/ope= nvpn/mailman/message/59246199/
Signed-off-by: Gert Doering <gert@...1386...= 296...>
---
M CMakeLists.txt
M src/openvpn/dhcp.c
M src/open= vpn/dhcp.h
M src/openvpn/tun.h
M tests/unit_tests/openvpn/Makefile.am=
M tests/unit_tests/openvpn/mock_msg.h
A tests/unit_tests/openvpn/tes= t_dhcp.c
7 files changed, 155 insertions(+), 4 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes=
/67/1267/5
diff --git a/CMakeLists.txt b/CMakeLists.txt
<= span>index 9e0b46e..b773dcb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -658,6 +658,7 @@
"test_auth_token"
&q= uot;test_buffer"
"test_crypto"
+ "test_dhcp&= quot;
"test_misc"
= "test_ncp"
"test_options_parse&q= uot;
@@ -910,6 +911,11 @@
)
endif ()

+ target_compile_definitions(test_dhcp PRIVATE = DHCP_UNIT_TEST)
+ = target_sources(test_dhcp PRIVATE
+ tests/unit_tests/openvpn/mock_get_random.c
<= span style=3D"color: hsl(120, 100%, 40%);">+ )

+
if (TARGET test_net= working)
target_link_options(test_networking PRIVA= TE -Wl,--wrap=3Dparse_line)
target_compile_options= (test_networking PRIVATE -UNDEBUG)
diff --git a/src/openvpn= /dhcp.c b/src/openvpn/dhcp.c
index 56f03f2..0893ec7 100644<= /span>
--- a/src/openvpn/dhcp.c
+++ b/src/openvpn/= dhcp.c
@@ -186,7 +186,7 @@
return 0;
}

-#if defined(_WIN32)
+#if defined(_WIN32) || defined(DHCP_UNIT_TEST)

#if defined(__GNUC__) || defined(__clang__)
= #pragma GCC diagnostic push
diff --git a/src/openvpn= /dhcp.h b/src/openvpn/dhcp.h
index 3fcd2b6..2ad31a6 100644<= /span>
--- a/src/openvpn/dhcp.h
+++ b/src/openvpn/= dhcp.h
@@ -93,7 +93,7 @@

= in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf);
=
-#if defined(_WIN32)
+#if defined(_WIN32) |= | defined(DHCP_UNIT_TEST)
#include "tun.h"

bool build_dhcp_options_string(struct buffer = *buf, const struct tuntap_options *o);
diff --git a/src/ope= nvpn/tun.h b/src/openvpn/tun.h
index 6562c22..741798d 10064= 4
--- a/src/openvpn/tun.h
+++ b/src/openvpn= /tun.h
@@ -59,7 +59,7 @@
#define DCO_WIN_R= EFERENCE_STRING "ovpn-dco"
#endif

-#if defined(_WIN32= ) || defined(TARGET_ANDROID)
+#if defined(_WIN32) || defined(TARGET_ANDROID) || defined(DHCP_UNI= T_TEST)

#define TUN_ADAPTER_INDEX_INVALI= D ((DWORD)-1)

diff --git a/tests/unit_tes= ts/openvpn/Makefile.am b/tests/unit_tests/openvpn/Makefile.am
index 50f4a11..17aa0ce 100644

--- a/tests/unit_tests/ope= nvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am=
@@ -6,7 +6,7 @@

AM_TEST= S_ENVIRONMENT =3D export LSAN_OPTIONS=3Dsuppressions=3D$(srcdir)/input/leak= _suppr.txt;

-test_binaries =3D argv_testdriver buffer_testdriver crypto_testdriv= er packet_id_testdriver auth_token_testdriver \
+test_binaries =3D argv_testdriver buffer_testdr= iver crypto_testdriver dhcp_testdriver packet_id_testdriver auth_token_test= driver \
ncp_testdriver misc_testdriver options_parse_tes= tdriver pkt_testdriver ssl_testdriver \
user_pass_testdri= ver push_update_msg_testdriver provider_testdriver socket_testdriver=

@@ -72,6 +72,15 @@
$(top_srcd= ir)/src/openvpn/win32-util.c \
$(top_srcdir)/src/openvpn/= mss.c

+dhcp_testdriver_CFLAGS =3D -I$(top_srcdir)/src/openvpn -I$(top_srcdir)= /src/compat @TEST_CFLAGS@ -DDHCP_UNIT_TEST
+dhcp_testdriver_LDFLAGS =3D @TEST_LDFLAGS@ -L$(top_s= rcdir)/src/openvpn
+d= hcp_testdriver_SOURCES =3D test_dhcp.c \
+ mock_msg.c mock_msg.h test_common.h \
+ mock_get_random.c \

+ $(top_srcdir)/src/openvpn/platfor= m.c \

+ $(top_srcdir)= /src/openvpn/buffer.c \
+ $(top_srcdir)/src/openvpn/win32-util.c
+
ssl_testdriver_CFLAGS =3D \
-I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_sr= cdir)/src/openvpn \
@TEST_CFLAGS@
diff --= git a/tests/unit_tests/openvpn/mock_msg.h b/tests/unit_tests/openvpn/mock_m= sg.h
index c6321dc..62afde5 100644
--- a/te= sts/unit_tests/openvpn/mock_msg.h
+++ b/tests/unit_tests/op= envpn/mock_msg.h
@@ -23,6 +23,8 @@
#ifndef= MOCK_MSG_H
#define MOCK_MSG_H
+#include "error.h"<= /span>
+
/*= *
* Mock debug level defaults to 0, which gives clean(-is= h) test reports. Call
* this function from your test dri= ver to increase debug output when you
diff --git a/tests/un= it_tests/openvpn/test_dhcp.c b/tests/unit_tests/openvpn/test_dhcp.c<= br>new file mode 100644
index 0000000..729ca58=
--- /dev/null
+++ b/tests/unit_tests/openvpn/test= _dhcp.c
@@ -0,0 +1,134 @@
+/*
+ * OpenVPN -- An application to securely tunnel IP networks+ * over a single = UDP port, with support for SSL/TLS-based
+ * session authentication and key exchange= ,
+ * pac= ket encryption, packet authentication, and
+ * packet compression.
+ *
+ * Copyright (C) 2025 OpenVPN Inc <sales@...515...= >
+ *
+ * This program is free softwar= e; you can redistribute it and/or modify

+ * it under the terms of the GNU General Public Licen= se version 2
+ * as = published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY W= ARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR P= URPOSE. See the
+ * = GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public Lice= nse along
+ * with t= his program; if not, see <https://www.gnu.org/licenses/>.
<= span style=3D"color: hsl(120, 100%, 40%);">+ */

+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include &qu= ot;syshead.h"
+<= /span>
+#include <stdio.h= >
+#include <st= dlib.h>
+#include = <stdarg.h>
+#in= clude <string.h>
+#include <cmocka.h>
+
+#inc= lude "test_common.h"
+#include "mock_msg.h"
+
+#include "dhcp.c"
+
+uint16_= t
+ip_checksum(const = sa_family_t af, const uint8_t *payload, const int len_payload,
+ const uint8_t *src_a= ddr, const uint8_t *dest_addr, const int proto)

+{
+ return 0;
+}
+const char *
+print_in_addr_t(in_ad= dr_t addr, unsigned int flags, struct gc_arena *gc)
+{
+ return "dummy";
+}
+
+static void=
+test_write_dhcp_sea= rch_str(void **state)
+{
+ struct gc_ar= ena gc =3D gc_new();
= + struct buffer out_buf =3D alloc_buf_gc(512, &gc);
+ struct buffer clear_buf =3D allo= c_buf_gc(512, &gc);
+ buf_clear(&clear_buf);
+ bool error =3D false;
+
+#define LONGDOMAIN "a-reaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa= aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa= aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa= aaaaaaaaaaaaaaaaaaaaaaally-long-domain"
+ const char *search_list[] =3D {
+ "openvpn.net",
+ "openvpn= .org",
+ = LONGDOMAIN,
+ = "subdomain." LONGDOMAIN ".top123", /* maximum length *= /
+ "subd= omain-" LONGDOMAIN "-top123", /* maximum length */+ "subdomain.&quo= t; LONGDOMAIN ".top1234", /* too long */
+ "sub..tld", = /* invalid */
+ };
+ const= unsigned char output_1[28] =3D "\x77\x1a\x07openvpn\x03net\x00\x07ope= nvpn\x03org";
+ = buf_clear(&out_buf);
+ write_dhcp_search_str(&out_buf, DHCP_DOMAIN_SEARCH, search_= list, 2, &error);
+ assert_memory_equal(BPTR(&out_buf), output_1, sizeof(output_1));<= /span>
+ assert_false(err= or);
+
+ /* buf too small */

= + struct buffer small_buf = =3D alloc_buf_gc(sizeof(output_1) - 1, &gc);
+ buf_clear(&small_buf);
+ write_dhcp_search_str(&smal= l_buf, DHCP_DOMAIN_SEARCH, search_list, 2, &error);

+ assert_memory_equal(BPTR(&small= _buf), BPTR(&clear_buf), buf_forward_capacity_total(&small_buf));
+ assert_true(error= );
+ error =3D fal= se;
+
+ const unsigned char output_2[0x= EC + 3 + 1] =3D "\x77\xEE\xEC" LONGDOMAIN;

+ buf_clear(&out_buf);
+ write_dhcp_search_str(&o= ut_buf, DHCP_DOMAIN_SEARCH, search_list + 2, 1, &error);

+ assert_memory_equal(BPTR(&= out_buf), output_2, sizeof(output_2));

+ assert_false(error);
+
+ const unsigned char output_3[0xEC + 3 + 10 + 7 + 1] =3D "\x77= \xFF\x09subdomain\xEC" LONGDOMAIN "\x06top123";
+ buf_clear(&out_buf);
+ write_dhcp_search_s= tr(&out_buf, DHCP_DOMAIN_SEARCH, search_list + 3, 1, &error);
+ assert_memory_equal(B= PTR(&out_buf), output_3, sizeof(output_3));
+ assert_false(error);
+
+ const unsigned char output_4[0xEC + 3 + 10 + 7 + 1] =3D = "\x77\xFF\xFDsubdomain-" LONGDOMAIN "-top123";+ buf_clear(&out_buf);=
+ write_dhcp_sear= ch_str(&out_buf, DHCP_DOMAIN_SEARCH, search_list + 4, 1, &error);
+ assert_memory_equ= al(BPTR(&out_buf), output_4, sizeof(output_4));
+ assert_false(error);
+
+ buf_clear(&out_buf);
+ write_dhcp_search_str(&out_buf, DHCP_D= OMAIN_SEARCH, search_list + 5, 1, &error);
+ assert_memory_equal(BPTR(&out_buf), BPTR= (&clear_buf), buf_forward_capacity_total(&clear_buf));
+ assert_true(error);
+ error =3D false;<= br>+
+ buf_clear(&out_buf);
+ write_dhcp_search_str(&out_bu= f, DHCP_DOMAIN_SEARCH, search_list, 3, &error);
+ assert_memory_equal(BPTR(&out_buf= ), BPTR(&clear_buf), buf_forward_capacity_total(&clear_buf));
+ assert_true(error);
+ error =3D false;<= /span>
+
+ /* FIXME: should probably throw an = error instead adding that \x00 ? */
+ const char output_5[12] =3D "\x77\x0a\x03sub\x00\x= 03tld";
+ buf= _clear(&out_buf);
+ write_dhcp_search_str(&out_buf, DHCP_DOMAIN_SEARCH, search_list += 6, 1, &error);
+= assert_memory_equal(BPTR(&out_buf), output_5, sizeof(output_5));

+ assert_false(error= );
+
+ gc_free(&gc);
+}

+
+int
+main(void)
+{
+ const struct CMUnitTest tests[] =3D= {
+ cmocka_un= it_test(test_write_dhcp_search_str),
+ };
+
+ return cmoc= ka_run_group_tests_name("dhcp", tests, NULL, NULL);
+}


To view, visit change 1267. To unsubscribe, or for help writing mail filte= rs, visit settin= gs.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I08e50030b1b692d351509f541e5= c0b03b5170615
Gerrit-Change-Number: 1267
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --sy5b8+Jcg20=--