From 00a006511b4b46298ac6cdebbeabb48d65d94ae8 Mon Sep 17 00:00:00 2001 From: emboss Date: Fri, 22 Jul 2011 02:21:26 +0000 Subject: [PATCH] * ext/openssl/ossl_digest.c: Check return value of EVP_DigestInit_ex. * ext/openssl/ossl_hmac.c: Check return value of HMAC_Init_ex. Thanks, Jared Jennings, for the patch. [ Ruby 1.9 - Bug #4944 ] [ruby-core:37670] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ ext/openssl/ossl_digest.c | 12 +++++++++--- ext/openssl/ossl_hmac.c | 10 +++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 610e490204..771b3142f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Jul 22 11:20:20 2011 Martin Bosslet + + * ext/openssl/ossl_digest.c: Check return value of EVP_DigestInit_ex. + * ext/openssl/ossl_hmac.c: Check return value of HMAC_Init_ex. + Thanks, Jared Jennings, for the patch. + [ Ruby 1.9 - Bug #4944 ] [ruby-core:37670] + Fri Jul 22 09:09:43 2011 Martin Bosslet * ext/openssl/ossl_engine.c: Avoid double free of ENGINE reference. diff --git a/ext/openssl/ossl_digest.c b/ext/openssl/ossl_digest.c index cb0cade1bf..ab165c4a84 100644 --- a/ext/openssl/ossl_digest.c +++ b/ext/openssl/ossl_digest.c @@ -68,7 +68,9 @@ ossl_digest_new(const EVP_MD *md) ret = ossl_digest_alloc(cDigest); GetDigest(ret, ctx); - EVP_DigestInit_ex(ctx, md, NULL); + if (EVP_DigestInit_ex(ctx, md, NULL) != 1) { + ossl_raise(eDigestError, "Digest initialization failed."); + } return ret; } @@ -122,7 +124,9 @@ ossl_digest_initialize(int argc, VALUE *argv, VALUE self) if (!NIL_P(data)) StringValue(data); GetDigest(self, ctx); - EVP_DigestInit_ex(ctx, md, NULL); + if (EVP_DigestInit_ex(ctx, md, NULL) != 1) { + ossl_raise(eDigestError, "Digest initialization failed."); + } if (!NIL_P(data)) return ossl_digest_update(self, data); return self; @@ -159,7 +163,9 @@ ossl_digest_reset(VALUE self) EVP_MD_CTX *ctx; GetDigest(self, ctx); - EVP_DigestInit_ex(ctx, EVP_MD_CTX_md(ctx), NULL); + if (EVP_DigestInit_ex(ctx, EVP_MD_CTX_md(ctx), NULL) != 1) { + ossl_raise(eDigestError, "Digest initialization failed."); + } return self; } diff --git a/ext/openssl/ossl_hmac.c b/ext/openssl/ossl_hmac.c index 15b37d09e9..5d29b8fc55 100644 --- a/ext/openssl/ossl_hmac.c +++ b/ext/openssl/ossl_hmac.c @@ -70,8 +70,10 @@ ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest) StringValue(key); GetHMAC(self, ctx); - HMAC_Init_ex(ctx, RSTRING_PTR(key), RSTRING_LENINT(key), - GetDigestPtr(digest), NULL); + if (HMAC_Init_ex(ctx, RSTRING_PTR(key), RSTRING_LENINT(key), + GetDigestPtr(digest), NULL) != 1) { + ossl_raise(eHMACError, "HMAC initialization failed."); + } return self; } @@ -180,7 +182,9 @@ ossl_hmac_reset(VALUE self) HMAC_CTX *ctx; GetHMAC(self, ctx); - HMAC_Init_ex(ctx, NULL, 0, NULL, NULL); + if (HMAC_Init_ex(ctx, NULL, 0, NULL, NULL) != 1) { + ossl_raise(eHMACError, "HMAC initialization failed"); + } return self; }