From: "selvanair (Code Review)" Date: Wed, 11 Sep 2024 03:19:07 +0000 References: Reply-To: selva.nair@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <3ba839f6d29460d1c132a0beee5f11cfaa93aac8-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="7C+JEcCky4Q="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Do not stop reading from file/uri when OPENSSL_STORE_load() returns e... List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --7C+JEcCky4Q= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/742?usp=3Demail to review the following change. Change subject: Do not stop reading from file/uri when OPENSSL_STORE_load()= returns error ...................................................................... Do not stop reading from file/uri when OPENSSL_STORE_load() returns error OPENSSL_STORE_load() can error and return NULL even when the file or URI still has readable objects left. Fix by iterating until OPENSSL_STORE_eof(). Also clear such errors to avoid misleading messages printed at the end by crypto_print_openssl_errors(). Change-Id: I2bfa9ffbd17d0599014d38b2a2fd319766cdb1e3 Signed-off-by: Selva Nair --- M src/openvpn/ssl_openssl.c 1 file changed, 42 insertions(+), 5 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/42/742/1 diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 0d845f4..5fd6572 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -813,6 +813,15 @@ } return 0; } + +static void +clear_ossl_store_error(OSSL_STORE_CTX *store_ctx) +{ + if (OSSL_STORE_error(store_ctx)) + { + ERR_clear_error(); + } +} #endif /* defined(HAVE_OPENSSL_STORE_API) */ /** @@ -864,7 +873,19 @@ { goto end; } - info =3D OSSL_STORE_load(store_ctx); + while (1) + { + info =3D OSSL_STORE_load(store_ctx); + if (info || OSSL_STORE_eof(store_ctx)) + { + break; + } + /* OPENSSL_STORE_load can return error and still have usable objec= ts to follow. + * ref: man OPENSSL_STORE_open + * Clear error and recurse through the file if info =3D NULL and e= of not reached + */ + clear_ossl_store_error(store_ctx); + } if (!info) { goto end; @@ -1099,7 +1120,19 @@ goto end; } - info =3D OSSL_STORE_load(store_ctx); + while (1) + { + info =3D OSSL_STORE_load(store_ctx); + if (info || OSSL_STORE_eof(store_ctx)) + { + break; + } + /* OPENSSL_STORE_load can return error and still have usable objec= ts to follow. + * ref: man OPENSSL_STORE_open + * Clear error and recurse through the file if info =3D NULL and e= of not reached. + */ + clear_ossl_store_error(store_ctx); + } if (!info) { goto end; @@ -1120,9 +1153,14 @@ OSSL_STORE_INFO_free(info); /* iterate through the store and add extra certificates if any to the = chain */ - info =3D OSSL_STORE_load(store_ctx); - while (info && !OSSL_STORE_eof(store_ctx)) + while (!OSSL_STORE_eof(store_ctx)) { + info =3D OSSL_STORE_load(store_ctx); + if (!info) + { + clear_ossl_store_error(store_ctx); + continue; + } x =3D OSSL_STORE_INFO_get1_CERT(info); if (x && SSL_CTX_add_extra_chain_cert(tls_ctx->ctx, x) !=3D 1) { @@ -1131,7 +1169,6 @@ break; } OSSL_STORE_INFO_free(info); - info =3D OSSL_STORE_load(store_ctx); } end: -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/742?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I2bfa9ffbd17d0599014d38b2a2fd319766cdb1e3 Gerrit-Change-Number: 742 Gerrit-PatchSet: 1 Gerrit-Owner: selvanair Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --7C+JEcCky4Q= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

selvanair would like plaisthos and flichtenheld to review this change.

Vi= ew Change

Do not stop reading from file/uri when OPENSSL_STORE_load() r=
eturns error

OPENSSL_STORE_load() can error and return NULL even whe= n the file or URI
still has readable objects left.

Fix by iterati= ng until OPENSSL_STORE_eof(). Also clear such errors to avoid
misleading= messages printed at the end by crypto_print_openssl_errors().

Chang= e-Id: I2bfa9ffbd17d0599014d38b2a2fd319766cdb1e3
Signed-off-by: Selva Nai= r <selva.nair@...277...>
---
M src/openvpn/ssl_openssl.c
1 f= ile changed, 42 insertions(+), 5 deletions(-)

git pull ssh://gerr=
it.openvpn.net:29418/openvpn refs/changes/42/742/1
diff --git a/src=
/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
index 0d= 845f4..5fd6572 100644
--- a/src/openvpn/ssl_openssl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -813,6 +813,1= 5 @@
}
return 0;
= }
+
+static void
+clear_ossl_store_error(OSSL_STORE_CTX *store= _ctx)
+{
+ if (OSSL_STORE_error(store_c= tx))

+ {+ ERR_clear_error();
+ }
+}
#endif /* defined= (HAVE_OPENSSL_STORE_API) */

/**@@ -864,7 +873,19 @@
{
= goto end;
}
- info =3D OSSL_STORE_load(store_ctx);
+ while (1)
+ {
+ info =3D OSSL_STORE_load(store_ctx);
+ if (info || OSSL_STORE_eof(s= tore_ctx))
+ {=
+ break;<= /span>
+ }
= + /* OPENSSL_STORE_load = can return error and still have usable objects to follow.
+ * ref: man OPENSSL_STORE_ope= n
+ * Clear e= rror and recurse through the file if info =3D NULL and eof not reached
+ */
+ clear_ossl_store_error(s= tore_ctx);

+ }
if (!info)
{
= goto end;
@@ -1099,7 +1120,19 @@
= goto end;
}

- info =3D OSSL_STORE_load(store_ctx);
+ while (1)+ {
+ info =3D OSSL_STORE_load(store_ct= x);
+ if (info= || OSSL_STORE_eof(store_ctx))
+ {
= + break;
+= }
+ /*= OPENSSL_STORE_load can return error and still have usable objects to follo= w.
+ * ref: m= an OPENSSL_STORE_open
+ * Clear error and recurse through the file if info =3D NULL and = eof not reached.
+ = */
+ cle= ar_ossl_store_error(store_ctx);
+ }
if (!info)
{
goto end;
@@ -1120,9 +1153,14 @@
OSSL_STORE_INFO_free(info);

<= span> /* iterate through the store and add extra certificates if any to= the chain */

- info= =3D OSSL_STORE_load(store_ctx);
- while (info && !OSSL_STORE_eof(store_ctx))+ while (!OSSL_STORE_eof(st= ore_ctx))
{
+ info =3D OSSL_STORE_load(store_ctx);
+ if (!info)
+ {
+ clear_ossl_store_error(store_ctx);
+ continue;=
+ } x =3D OSSL_STORE_INFO_get1_CERT(info);
= if (x && SSL_CTX_add_extra_chain_cert(tls_ctx->ctx, x) !=3D= 1)
{
@@ -1131,7 +1169,6 @@=
break;
}
= OSSL_STORE_INFO_free(info);
- info =3D OSSL_STORE_load(store_ctx);
= }

end:

To view, visit change 742. To unsubscribe, or for help writing mail filte= rs, visit settings.

<= div itemscope itemtype=3D"http://schema.org/EmailMessage">
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2bfa9ffbd17d0599014d38b2a2f= d319766cdb1e3
Gerrit-Change-Number: 742
Gerrit-PatchSet: 1
Gerrit-Owner: selvanair <selva.nair@...1354...= ..>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--7C+JEcCky4Q=--