diff options
author | Kazuki Yamaguchi <[email protected]> | 2022-09-02 18:14:57 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <[email protected]> | 2022-10-17 16:35:35 +0900 |
commit | 4fb2845c7b71d94f01a224020e4eb91c99f99d66 (patch) | |
tree | 0622ae7d10f091c6a081d6f8665318dc80b4e28a /ext/openssl/ossl_pkey.c | |
parent | 10f93a8bd787658996f08b13a0e564eaf3f41489 (diff) |
[ruby/openssl] pkey: clear error queue before each OSSL_DECODER_from_bio() call
Fix potential error queue leak.
https://github.com/ruby/openssl/commit/3992b6f208
Diffstat (limited to 'ext/openssl/ossl_pkey.c')
-rw-r--r-- | ext/openssl/ossl_pkey.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index 0dafa6dc71..0effb3e96a 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -99,17 +99,20 @@ ossl_pkey_read_generic(BIO *bio, VALUE pass) /* First check DER */ if (OSSL_DECODER_from_bio(dctx, bio) == 1) goto out; + OSSL_BIO_reset(bio); /* Then check PEM; multiple OSSL_DECODER_from_bio() calls may be needed */ - OSSL_BIO_reset(bio); if (OSSL_DECODER_CTX_set_input_type(dctx, "PEM") != 1) goto out; - while (OSSL_DECODER_from_bio(dctx, bio) != 1) { - if (BIO_eof(bio)) + while (1) { + if (OSSL_DECODER_from_bio(dctx, bio) == 1) goto out; + if (BIO_eof(bio)) + break; pos2 = BIO_tell(bio); if (pos2 < 0 || pos2 <= pos) - goto out; + break; + ossl_clear_error(); pos = pos2; } |