summaryrefslogtreecommitdiff
path: root/ext/digest/digest.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-15 14:58:53 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-15 14:58:53 +0000
commit6046b9f149ec748a11d7b23c6cf485fb3e079e5a (patch)
treee6bfb9fc90af6808b6b0ba69666c9aa8f1759db0 /ext/digest/digest.c
parenta3f50234bc4cd0dd66c6283495dd3d07da6b48e1 (diff)
digest.c: raise exception on init failure
* ext/digest/digest.c: expect digest init and finish functions to indicate success or failure; raise exception on failure. [ruby-core:61614] [Bug #9659] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/digest/digest.c')
-rw-r--r--ext/digest/digest.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index f1592f4..2231452 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -521,7 +521,7 @@ get_digest_base_metadata(VALUE klass)
Data_Get_Struct(obj, rb_digest_metadata_t, algo);
switch (algo->api_version) {
- case 2:
+ case 3:
break;
/*
@@ -535,6 +535,14 @@ get_digest_base_metadata(VALUE klass)
return algo;
}
+static inline void
+algo_init(const rb_digest_metadata_t *algo, void *pctx)
+{
+ if (algo->init_func(pctx) != 1) {
+ rb_raise(rb_eRuntimeError, "Digest initialization failed.");
+ }
+}
+
static VALUE
rb_digest_base_alloc(VALUE klass)
{
@@ -549,7 +557,7 @@ rb_digest_base_alloc(VALUE klass)
algo = get_digest_base_metadata(klass);
pctx = xmalloc(algo->ctx_size);
- algo->init_func(pctx);
+ algo_init(algo, pctx);
obj = Data_Wrap_Struct(klass, 0, xfree, pctx);
@@ -587,7 +595,7 @@ rb_digest_base_reset(VALUE self)
Data_Get_Struct(self, void, pctx);
- algo->init_func(pctx);
+ algo_init(algo, pctx);
return self;
}
@@ -625,7 +633,7 @@ rb_digest_base_finish(VALUE self)
algo->finish_func(pctx, (unsigned char *)RSTRING_PTR(str));
/* avoid potential coredump caused by use of a finished context */
- algo->init_func(pctx);
+ algo_init(algo, pctx);
return str;
}