Skip to content

Commit

Permalink
OpenSSL: pop pushed error after each try of reading. (merged form CRu…
Browse files Browse the repository at this point in the history
…by 1.9.2 p290)

ruby/ruby@d5b1fde
  • Loading branch information
Watson1978 committed Jul 29, 2011
1 parent 0158b2b commit b9cfd43
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ext/openssl/ossl_pkey_dh.c
Expand Up @@ -170,10 +170,14 @@ ossl_dh_initialize(VALUE self, SEL sel, int argc, VALUE *argv)
dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
if (!dh){
(void)BIO_reset(in);
(void)ERR_get_error();
dh = d2i_DHparams_bio(in, NULL);
}
BIO_free(in);
if (!dh) ossl_raise(eDHError, NULL);
if (!dh) {
(void)ERR_get_error();
ossl_raise(eDHError, NULL);
}
}
if (!EVP_PKEY_assign_DH(pkey, dh)) {
DH_free(dh);
Expand Down
9 changes: 8 additions & 1 deletion ext/openssl/ossl_pkey_dsa.c
Expand Up @@ -162,22 +162,29 @@ ossl_dsa_initialize(VALUE self, SEL sel, int argc, VALUE *argv)
dsa = PEM_read_bio_DSAPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
if (!dsa) {
(void)BIO_reset(in);
(void)ERR_get_error();
dsa = PEM_read_bio_DSAPublicKey(in, NULL, NULL, NULL);
}
if (!dsa) {
(void)BIO_reset(in);
(void)ERR_get_error();
dsa = PEM_read_bio_DSA_PUBKEY(in, NULL, NULL, NULL);
}
if (!dsa) {
(void)BIO_reset(in);
(void)ERR_get_error();
dsa = d2i_DSAPrivateKey_bio(in, NULL);
}
if (!dsa) {
(void)BIO_reset(in);
(void)ERR_get_error();
dsa = d2i_DSA_PUBKEY_bio(in, NULL);
}
BIO_free(in);
if (!dsa) ossl_raise(eDSAError, "Neither PUB key nor PRIV key:");
if (!dsa) {
(void)ERR_get_error();
ossl_raise(eDSAError, "Neither PUB key nor PRIV key:");
}
}
if (!EVP_PKEY_assign_DSA(pkey, dsa)) {
DSA_free(dsa);
Expand Down
4 changes: 4 additions & 0 deletions ext/openssl/ossl_pkey_ec.c
Expand Up @@ -187,14 +187,17 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
ec = PEM_read_bio_ECPrivateKey(in, NULL, NULL, NULL);
if (!ec) {
(void)BIO_reset(in);
(void)ERR_get_error();
ec = PEM_read_bio_EC_PUBKEY(in, NULL, NULL, NULL);
}
if (!ec) {
(void)BIO_reset(in);
(void)ERR_get_error();
ec = d2i_ECPrivateKey_bio(in, NULL);
}
if (!ec) {
(void)BIO_reset(in);
(void)ERR_get_error();
ec = d2i_EC_PUBKEY_bio(in, NULL);
}

Expand All @@ -204,6 +207,7 @@ static VALUE ossl_ec_key_initialize(int argc, VALUE *argv, VALUE self)
const char *name = StringValueCStr(arg);
int nid = OBJ_sn2nid(name);

(void)ERR_get_error();
if (nid == NID_undef)
ossl_raise(eECError, "unknown curve name (%s)\n", name);

Expand Down
10 changes: 9 additions & 1 deletion ext/openssl/ossl_pkey_rsa.c
Expand Up @@ -152,26 +152,34 @@ ossl_rsa_initialize(VALUE self, SEL sel, int argc, VALUE *argv)
rsa = PEM_read_bio_RSAPrivateKey(in, NULL, ossl_pem_passwd_cb, passwd);
if (!rsa) {
(void)BIO_reset(in);
(void)ERR_get_error();
rsa = PEM_read_bio_RSAPublicKey(in, NULL, NULL, NULL);
}
if (!rsa) {
(void)BIO_reset(in);
(void)ERR_get_error();
rsa = PEM_read_bio_RSA_PUBKEY(in, NULL, NULL, NULL);
}
if (!rsa) {
(void)BIO_reset(in);
(void)ERR_get_error();
rsa = d2i_RSAPrivateKey_bio(in, NULL);
}
if (!rsa) {
(void)BIO_reset(in);
(void)ERR_get_error();
rsa = d2i_RSAPublicKey_bio(in, NULL);
}
if (!rsa) {
(void)BIO_reset(in);
(void)ERR_get_error();
rsa = d2i_RSA_PUBKEY_bio(in, NULL);
}
BIO_free(in);
if (!rsa) ossl_raise(eRSAError, "Neither PUB key nor PRIV key:");
if (!rsa) {
(void)ERR_get_error();
ossl_raise(eRSAError, "Neither PUB key nor PRIV key:");
}
}
if (!EVP_PKEY_assign_RSA(pkey, rsa)) {
RSA_free(rsa);
Expand Down

0 comments on commit b9cfd43

Please sign in to comment.