From: "flichtenheld (Code Review)" Date: Fri, 30 Jan 2026 16:11:10 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <717cb70604af930a1a5e2ba47c4d2fb1b74f0ed6-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="uNOjcdVYNnA="; 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: plaisthos Cc: openvpn-devel --uNOjcdVYNnA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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/+/1503?usp=3Demail to review the following change. 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 --- M src/openvpn/ssl_ncp.c M tests/unit_tests/openvpn/test_ncp.c 2 files changed, 18 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/1503/1 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: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ib0d2b9520e4a77a9f4bf70ce092f76ca73608537 Gerrit-Change-Number: 1503 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --uNOjcdVYNnA= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

ssl_ncp: Fix length check in mutate_ncp_cip=
her_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: Ib0d2b9520e4a77a9f4bf70ce092f= 76ca73608537
Signed-off-by: Frank Lichtenheld <frank@...2641...>---
M src/openvpn/ssl_ncp.c
M tests/unit_tests/openvpn/test_ncp.c2 files changed, 18 insertions(+), 14 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/03/1503/1=
diff --git a/src/openvpn/ssl_ncp.c b/src/openvpn/ssl_ncp.c<=
br>index 500e09d..fdac6925 100644
--- a/src/openvpn/s= sl_ncp.c
+++ b/src/openvpn/ssl_ncp.c
@@ -92= ,11 +92,6 @@
}
}

-#if defined(__GNUC__) ||= defined(__clang__)
-#p= ragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif

-
char *
mutate_n= cp_cipher_list(const char *list, struct gc_arena *gc)
{
@@ -168,7 +163,7 @@
}
=
/* Ensure buffer has capacity for ciph= er name + : + \0 */
- = if (!(buf_forward_capacity(&new_list) > strlen(ovpn_cipher= _name) + 2))
+ = if (buf_forward_capacity(&new_list) < (int)strlen(ovpn_cipher_n= ame) + 2)
{
m= sg(M_WARN, "Length of --data-ciphers is over the "
"limit of 127 chars");

<= span>@@ -207,10 +202,6 @@
o->ncp_ciphers =3D ncp_ci= phers;
}

-#if defined(__GNUC__) || defined(__clang__)-#pragma GCC diagnostic pop
-#endif
-
bool
t= ls_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 10064= 4
--- 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("AE= S-256-GCM:vollbit", &gc), NULL);
assert_ptr_e= qual(mutate_ncp_cipher_list("", &gc), NULL);
=
- assert_ptr_equal= (mutate_ncp_cipher_list("ChaCha20-Poly1305:ChaCha20-Poly1305:ChaCha20-= Poly1305:"
- = "ChaCha20-Poly1305:ChaCha20-Poly= 1305:ChaCha20-Poly1305:"
- "ChaCha20-Poly1305= ",
- = &gc),
+ const char long_string[MAX_NCP_CIPHERS_LENGTH] =3D<= /span>
+ "CHACHA= 20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:"
+ "CHACHA20-POLY1305:CHACHA20= -POLY1305:CHACHA20-POLY1305:"
+ "CHACHA20-POLY1305";
+ const char longer_string[MAX_NCP_CIPH= ERS_LENGTH + 1] =3D
+= "CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:"<= /span>
+ "CHACHA= 20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:"
+ "CHACHA20-POLY1305:";<= /span>
+ const char longe= st_string[] =3D
+ = "CHACHA20-POLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:"
+ "CHACHA20-P= OLY1305:CHACHA20-POLY1305:CHACHA20-POLY1305:"
+ "CHACHA20-POLY1305:CHACHA20-POL= Y1305";
+ ass= ert_string_equal(mutate_ncp_cipher_list(long_string, &gc),
+ long_str= ing);

+ assert_str= ing_equal(mutate_ncp_cipher_list(longer_string, &gc),
+ long_string);=
+ assert_ptr_equa= l(mutate_ncp_cipher_list(longest_string, &gc),
= NULL);

#ifdef ENABLE_CRYPT= O_OPENSSL

To view, visit change 1503. To un= subscribe, or for help writing mail filters, visit settings.

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