Skip to content

Commit 3992b6f

Browse files
committed
pkey: clear error queue before each OSSL_DECODER_from_bio() call
Fix potential error queue leak.
1 parent bff4080 commit 3992b6f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ext/openssl/ossl_pkey.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,20 @@ ossl_pkey_read_generic(BIO *bio, VALUE pass)
9999
/* First check DER */
100100
if (OSSL_DECODER_from_bio(dctx, bio) == 1)
101101
goto out;
102+
OSSL_BIO_reset(bio);
102103

103104
/* Then check PEM; multiple OSSL_DECODER_from_bio() calls may be needed */
104-
OSSL_BIO_reset(bio);
105105
if (OSSL_DECODER_CTX_set_input_type(dctx, "PEM") != 1)
106106
goto out;
107-
while (OSSL_DECODER_from_bio(dctx, bio) != 1) {
108-
if (BIO_eof(bio))
107+
while (1) {
108+
if (OSSL_DECODER_from_bio(dctx, bio) == 1)
109109
goto out;
110+
if (BIO_eof(bio))
111+
break;
110112
pos2 = BIO_tell(bio);
111113
if (pos2 < 0 || pos2 <= pos)
112-
goto out;
114+
break;
115+
ossl_clear_error();
113116
pos = pos2;
114117
}
115118

0 commit comments

Comments
 (0)