From: "cron2 (Code Review)" Date: Wed, 4 Mar 2026 16:20:52 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <1d0810771fbf3de4de7c702d9f86d3325b5058a2-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="AUjUyeVHjVw="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: ssl_ncp: Fix length check in mutate_ncp_cipher_list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: plaisthos , openvpn-devel --AUjUyeVHjVw= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/15= 03?usp=3Demail ) Change subject: ssl_ncp: Fix length check in mutate_ncp_cipher_list ...................................................................... ssl_ncp: Fix length check in mutate_ncp_cipher_list * Make it more readable by removing a level of negation * Fix an off-by-one error. It accepted one char fewer than allowed. * Slightly improve the UT. Change-Id: Ib0d2b9520e4a77a9f4bf70ce092f76ca73608537 Signed-off-by: Frank Lichtenheld Acked-by: Arne Schwabe Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1503 Message-Id: <20260302181627.29008-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35= 828.html Signed-off-by: Gert Doering --- M src/openvpn/ssl_ncp.c M tests/unit_tests/openvpn/test_ncp.c 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c index 500e09d..fdac6925 100644 --- a/src/openvpn/ssl_ncp.c +++ b/src/openvpn/ssl_ncp.c @@ -92,11 +92,6 @@ } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-compare" -#endif - char * mutate_ncp_cipher_list(const char *list, struct gc_arena *gc) { @@ -168,7 +163,7 @@ } /* Ensure buffer has capacity for cipher name + : + \0 */ - if (!(buf_forward_capacity(&new_list) > strlen(ovpn_cipher_nam= e) + 2)) + if (buf_forward_capacity(&new_list) < (int)strlen(ovpn_cipher_= name) + 2) { msg(M_WARN, "Length of --data-ciphers is over the " "limit of 127 chars"); @@ -207,10 +202,6 @@ o->ncp_ciphers =3D ncp_ciphers; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - bool tls_item_in_cipher_list(const char *item, const char *list) { diff --git a/tests/unit_tests/openvpn/test_ncp.c b/tests/unit_tests/openvpn= /test_ncp.c index 9f569a7..52a41ee 100644 --- a/tests/unit_tests/openvpn/test_ncp.c +++ b/tests/unit_tests/openvpn/test_ncp.c @@ -123,10 +123,23 @@ assert_ptr_equal(mutate_ncp_cipher_list("AES-256-GCM:vollbit", &gc), N= ULL); assert_ptr_equal(mutate_ncp_cipher_list("", &gc), NULL); - assert_ptr_equal(mutate_ncp_cipher_list("ChaCha20-Poly1305:ChaCha20-Po= ly1305:ChaCha20-Poly1305:" - "ChaCha20-Poly1305:ChaCha20-Po= ly1305:ChaCha20-Poly1305:" - "ChaCha20-Poly1305", - &gc), + const char long_string[MAX_NCP_CIPHERS_LENGTH] =3D + "CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:" + "CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:" + "CHACHA20-POLY1305"; + const char longer_string[MAX_NCP_CIPHERS_LENGTH + 1] =3D + "CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:" + "CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:" + "CHACHA20-POLY1305:"; + const char longest_string[] =3D + "CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:" + "CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:" + "CHACHA20-POLY1305:CHACHA20-POLY1305"; + assert_string_equal(mutate_ncp_cipher_list(long_string, &gc), + long_string); + assert_string_equal(mutate_ncp_cipher_list(longer_string, &gc), + long_string); + assert_ptr_equal(mutate_ncp_cipher_list(longest_string, &gc), NULL); #ifdef ENABLE_CRYPTO_OPENSSL -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1503?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ib0d2b9520e4a77a9f4bf70ce092f76ca73608537 Gerrit-Change-Number: 1503 Gerrit-PatchSet: 6 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --AUjUyeVHjVw= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

ssl_ncp: Fix length check in mutate_ncp_cipher_l=
ist

* Make it more readable by removing a level of negation
* Fix= an off-by-one error. It accepted one char fewer than
allowed.
* Sl= ightly improve the UT.

Change-Id: Ib0d2b9520e4a77a9f4bf70ce092f76ca7= 3608537
Signed-off-by: Frank Lichtenheld <frank@...2641...>
Ack= ed-by: Arne Schwabe <arne-openvpn@...1227...>
Gerrit URL: https://= gerrit.openvpn.net/c/openvpn/+/1503
Message-Id: <20260302181627.29008= -1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@...465...= ists.sourceforge.net/msg35828.html
Signed-off-by: Gert Doering <gert@= ...1296...>
---
M src/openvpn/ssl_ncp.c
M tests/unit_tests/open= vpn/test_ncp.c
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c
index 500e09d..fdac6925 100644
--- a/src/openvpn/ssl_ncp= .c
+++ b/src/openvpn/ssl_ncp.c
@@ -92,11 +9= 2,6 @@
}
}
-#if defined(__GNUC__) || defin= ed(__clang__)
-#pragma = GCC diagnostic push
-#p= ragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
char *
mutate_ncp_cip= her_list(const char *list, struct gc_arena *gc)
{@@ -168,7 +163,7 @@
}
=
/* Ensure buffer has capacity for cipher nam= e + : + \0 */
- = if (!(buf_forward_capacity(&new_list) > strlen(ovpn_cipher_name)= + 2))
+ i= f (buf_forward_capacity(&new_list) < (int)strlen(ovpn_cipher_name) += 2)
{
msg(M_W= ARN, "Length of --data-ciphers is over the "
= "limit of 127 chars");
@= @ -207,10 +202,6 @@
o->ncp_ciphers =3D ncp_ciphers;=
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
= -#endif
-
bool
tls_ite= m_in_cipher_list(const char *item, const char *list)
{

diff --git a/tests/unit_tests/openvpn/test_ncp.c b/tests/unit_= tests/openvpn/test_ncp.c
index 9f569a7..52a41ee 100644
--- a/tests/unit_tests/openvpn/test_ncp.c
+++ b= /tests/unit_tests/openvpn/test_ncp.c
@@ -123,10 +123,23 @@<= /span>
assert_ptr_equal(mutate_ncp_cipher_list("AES-256-= GCM:vollbit", &gc), NULL);
assert_ptr_equal(m= utate_ncp_cipher_list("", &gc), NULL);

- assert_ptr_equal(mutat= e_ncp_cipher_list("ChaCha20-Poly1305:ChaCha20-Poly1305:ChaCha20-Poly13= 05:"
- = "ChaCha20-Poly1305:ChaCha20-Poly1305:C= haCha20-Poly1305:"
- "ChaCha20-Poly1305"= ,
- = &gc),
+ const char long_string[MAX_NCP_CIPHERS_LENGTH] =3D=
+ "CHACHA20-POL= Y1305:CHACHA20-POLY1305:CHACHA20-POLY1305:"
+ "CHACHA20-POLY1305:CHACHA20-POLY1= 305:CHACHA20-POLY1305:"
+ "CHACHA20-POLY1305";
+ const char longer_string[MAX_NCP_CIPHERS_LE= NGTH + 1] =3D
+ = "CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:"=
+ "CHACHA20-POL= Y1305:CHACHA20-POLY1305:CHACHA20-POLY1305:"
+ "CHACHA20-POLY1305:";=
+ const char longest_str= ing[] =3D
+ &q= uot;CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:"
= + "CHACHA20-POLY130= 5:CHACHA20-POLY1305:CHACHA20-POLY1305:"
+ "CHACHA20-POLY1305:CHACHA20-POLY1305&= quot;;
+ assert_st= ring_equal(mutate_ncp_cipher_list(long_string, &gc),
+ long_string);<= /span>
+ assert_string_eq= ual(mutate_ncp_cipher_list(longer_string, &gc),
+ long_string);

+ assert_ptr_equal(mu= tate_ncp_cipher_list(longest_string, &gc),
= NULL);

#ifdef ENABLE_CRYPTO_OP= ENSSL

To view, visit change 1503. To unsubs= cribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib0d2b9520e4a77a9f4bf70ce092= f76ca73608537
Gerrit-Change-Number: 1503
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --AUjUyeVHjVw=--