From: "cron2 (Code Review)" Date: Wed, 11 Sep 2024 12:26:19 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., selva.nair@...277..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <431245170daec358e009d3be500a9370e31a6ad5-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="OwMY2+e0+ew="; 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: selvanair , plaisthos , flichtenheld Cc: openvpn-devel --OwMY2+e0+ew= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#2) to the change originally created by= selvanair. ( http://gerrit.openvpn.net/c/openvpn/+/742?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by plaisthos 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 Acked-by: Arne Schwabe Message-Id: <20240911104941.19429-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29= 187.html Signed-off-by: Gert Doering --- 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/2 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: 2 Gerrit-Owner: selvanair Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --OwMY2+e0+ew= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #2 to the change originally cr= eated by selvanair.

View Change

The following approvals got outdated= and were removed: Code-Review+2 by plaisthos

Do not stop reading from file/uri when OPENSSL_S=
TORE_load() returns error

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

F= ix by iterating until OPENSSL_STORE_eof(). Also clear such errors to avoid<= br>misleading messages printed at the end by crypto_print_openssl_errors().=

Change-Id: I2bfa9ffbd17d0599014d38b2a2fd319766cdb1e3
Signed-off-= by: Selva Nair <selva.nair@...277...>
Acked-by: Arne Schwabe <a= rne-openvpn@...1227...>
Message-Id: <20240911104941.19429-1-gert@...220...= ..1296...>
URL: https://www.mail-archive.com/openvpn-devel@...1439...= ceforge.net/msg29187.html
Signed-off-by: Gert Doering <gert@...2132...= .>
---
M src/openvpn/ssl_openssl.c
1 file changed, 42 insertion= s(+), 5 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/open=
vpn refs/changes/42/742/2
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/open= vpn/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,1= 9 @@
{
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))
<= span style=3D"color: hsl(120, 100%, 40%);">+ {
+ break;
+ }
+ /* OPENSSL_STORE_load can return error and = still have usable objects to follow.
+ * ref: man OPENSSL_STORE_open
+ * Clear error and recurse thro= ugh the file if info =3D NULL and eof 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 objects to follow.

+ * ref: man OPENSSL_STORE_open
+ * Clear error= and recurse through the file if info =3D NULL and eof not reached.<= br>+ */
+ clear_ossl_store_error(stor= e_ctx);

+ }=
if (!info)
{
g= oto end;
@@ -1120,9 +1153,14 @@
OSSL_S= TORE_INFO_free(info);

/* iterate thr= ough the store and add extra certificates if any to the chain */
= - info =3D OSSL_STORE_load(sto= re_ctx);
- while (in= fo && !OSSL_STORE_eof(store_ctx))
+ while (!OSSL_STORE_eof(store_ctx))
{

+ inf= o =3D OSSL_STORE_load(store_ctx);
+ if (!info)
+ {
+ 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);
- i= nfo =3D OSSL_STORE_load(store_ctx);
}
=
end:

To view, visit = change 74= 2. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I2bfa9ffbd17d0599014d38b2a2f= d319766cdb1e3
Gerrit-Change-Number: 742
Gerrit-PatchSet: 2
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-MessageType: newpatchset
--OwMY2+e0+ew=--