From: "flichtenheld (Code Review)" Date: Fri, 30 Jan 2026 16:11:16 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Te2/Gm5u5Sk="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: ssl_verify_openssl: Clean up extract_x509_extension List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --Te2/Gm5u5Sk= 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/+/1507?usp=3Demail to review the following change. Change subject: ssl_verify_openssl: Clean up extract_x509_extension ...................................................................... ssl_verify_openssl: Clean up extract_x509_extension * Avoid sign-compare warning when comparing string lengths * Use the nicer alias rfc822Name instead of the general ia5 from the GENERAL_NAME union. * Use the official ASN1_STRING_length API instead of accessing the struct directly. * C11 changes Change-Id: I23cc00aee47aef007ab2e7d50b52c6de299505db Signed-off-by: Frank Lichtenheld --- M src/openvpn/ssl_verify_openssl.c 1 file changed, 5 insertions(+), 16 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1507/1 diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_open= ssl.c index 58f665c..90a8a51 100644 --- a/src/openvpn/ssl_verify_openssl.c +++ b/src/openvpn/ssl_verify_openssl.c @@ -118,16 +118,10 @@ return nid =3D=3D NID_subject_alt_name || nid =3D=3D NID_issuer_alt_na= me; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-compare" -#endif - static bool extract_x509_extension(X509 *cert, char *fieldname, char *out, size_t size) { bool retval =3D false; - char *buf =3D 0; if (!x509_username_field_ext_supported(fieldname)) { @@ -139,17 +133,15 @@ GENERAL_NAMES *extensions =3D X509_get_ext_d2i(cert, nid, NULL, NULL); if (extensions) { - int numalts; - int i; /* get amount of alternatives, * RFC2459 claims there MUST be at least * one, but we don't depend on it... */ - numalts =3D sk_GENERAL_NAME_num(extensions); + int numalts =3D sk_GENERAL_NAME_num(extensions); /* loop through all alternatives */ - for (i =3D 0; i < numalts; i++) + for (int i =3D 0; i < numalts; i++) { /* get a handle to alternative name number i */ const GENERAL_NAME *name =3D sk_GENERAL_NAME_value(extensions,= i); @@ -157,11 +149,12 @@ switch (name->type) { case GEN_EMAIL: - if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->= d.ia5) < 0) + char *buf =3D NULL; + if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->= d.rfc822Name) < 0) { continue; } - if (strlen(buf) !=3D name->d.ia5->length) + if ((ssize_t)strlen(buf) !=3D ASN1_STRING_length(name-= >d.rfc822Name)) { msg(D_TLS_ERRORS, "ASN1 ERROR: string contained te= rminating zero"); OPENSSL_free(buf); @@ -185,10 +178,6 @@ return retval; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - /* * Extract a field from an X509 subject name. * -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1507?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: I23cc00aee47aef007ab2e7d50b52c6de299505db Gerrit-Change-Number: 1507 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --Te2/Gm5u5Sk= 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_verify_openssl: Clean up extract_x509_e=
xtension

* Avoid sign-compare warning when comparing string
len= gths
* Use the nicer alias rfc822Name instead of the general ia5
fr= om the GENERAL_NAME union.
* Use the official ASN1_STRING_length API ins= tead of accessing
the struct directly.
* C11 changes

Change-= Id: I23cc00aee47aef007ab2e7d50b52c6de299505db
Signed-off-by: Frank Licht= enheld <frank@...2641...>
---
M src/openvpn/ssl_verify_openssl.= c
1 file changed, 5 insertions(+), 16 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1507/=
1
diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_v=
erify_openssl.c
index 58f665c..90a8a51 100644
--- a/src/openvpn/ssl_verify_openssl.c
+++ b/src/openvpn= /ssl_verify_openssl.c
@@ -118,16 +118,10 @@
return nid =3D=3D NID_subject_alt_name || nid =3D=3D NID_issuer_alt_n= ame;
}

-#if defined(__GNUC__) || defined(__clang__)
<= span style=3D"color: hsl(0, 100%, 40%);">-#pragma GCC diagnostic push

-#pragma GCC diagnostic igno= red "-Wsign-compare"
-#endif
-
static bool
extract_x509_extension(X509 *cert,= char *fieldname, char *out, size_t size)
{
bool retval =3D false;

- char *buf =3D 0;

if (!x5= 09_username_field_ext_supported(fieldname))
{@@ -139,17 +133,15 @@
GENERAL_NAMES *extension= s =3D X509_get_ext_d2i(cert, nid, NULL, NULL);
if (ext= ensions)
{
- int numalts;
- int i;
/* get amount of alternati= ves,
* RFC2459 claims there MUST be at least
* one, but we don't depend on it...
*/


- numalts =3D sk_GENERAL_NAME_num(extensions);
= + int numalts =3D sk_GEN= ERAL_NAME_num(extensions);

/* lo= op through all alternatives */
- for (i =3D 0; i < numalts; i++)
+ for (int i =3D 0; i < numalts;= i++)
{
/* get a hand= le to alternative name number i */
const GENER= AL_NAME *name =3D sk_GENERAL_NAME_value(extensions, i);
@@ = -157,11 +149,12 @@
switch (name->type)
{
case GEN_EMAIL:=
- i= f (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.ia5) < 0)<= /span>
+ = char *buf =3D NULL;
+= if (ASN1_STRING_to_UTF8((unsigned char **)&buf, nam= e->d.rfc822Name) < 0)
{ continue;
= }
- = if (strlen(buf) !=3D name->d.ia5->length)
+ if ((ssize_t)strlen(b= uf) !=3D ASN1_STRING_length(name->d.rfc822Name))
= {
msg(D_TLS_ERRORS, = "ASN1 ERROR: string contained terminating zero");
OPENSSL_free(buf);

@@ -185,10 +17= 8,6 @@
return retval;
}

-#if defined(__GNU= C__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
/*
* Extract a field from an X509 subject na= me.
*

To view, visit = change 1= 507. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23cc00aee47aef007ab2e7d50b5= 2c6de299505db
Gerrit-Change-Number: 1507
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...>
= --Te2/Gm5u5Sk=--