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
This commit is contained in:
parent
a3f50234bc
commit
6046b9f149
@ -1,3 +1,9 @@
|
|||||||
|
Tue Jul 15 23:58:59 2014 Jared Jennings <jared.jennings.ctr@us.af.mil>
|
||||||
|
|
||||||
|
* ext/digest/digest.c: expect digest init and finish functions to
|
||||||
|
indicate success or failure; raise exception on failure.
|
||||||
|
[ruby-core:61614] [Bug #9659]
|
||||||
|
|
||||||
Tue Jul 15 20:31:40 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
Tue Jul 15 20:31:40 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||||
|
|
||||||
* ext/win32ole/win32ole.c: modify document for WIN32OLE_RECORD.
|
* ext/win32ole/win32ole.c: modify document for WIN32OLE_RECORD.
|
||||||
|
@ -521,7 +521,7 @@ get_digest_base_metadata(VALUE klass)
|
|||||||
Data_Get_Struct(obj, rb_digest_metadata_t, algo);
|
Data_Get_Struct(obj, rb_digest_metadata_t, algo);
|
||||||
|
|
||||||
switch (algo->api_version) {
|
switch (algo->api_version) {
|
||||||
case 2:
|
case 3:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -535,6 +535,14 @@ get_digest_base_metadata(VALUE klass)
|
|||||||
return algo;
|
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
|
static VALUE
|
||||||
rb_digest_base_alloc(VALUE klass)
|
rb_digest_base_alloc(VALUE klass)
|
||||||
{
|
{
|
||||||
@ -549,7 +557,7 @@ rb_digest_base_alloc(VALUE klass)
|
|||||||
algo = get_digest_base_metadata(klass);
|
algo = get_digest_base_metadata(klass);
|
||||||
|
|
||||||
pctx = xmalloc(algo->ctx_size);
|
pctx = xmalloc(algo->ctx_size);
|
||||||
algo->init_func(pctx);
|
algo_init(algo, pctx);
|
||||||
|
|
||||||
obj = Data_Wrap_Struct(klass, 0, xfree, 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);
|
Data_Get_Struct(self, void, pctx);
|
||||||
|
|
||||||
algo->init_func(pctx);
|
algo_init(algo, pctx);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -625,7 +633,7 @@ rb_digest_base_finish(VALUE self)
|
|||||||
algo->finish_func(pctx, (unsigned char *)RSTRING_PTR(str));
|
algo->finish_func(pctx, (unsigned char *)RSTRING_PTR(str));
|
||||||
|
|
||||||
/* avoid potential coredump caused by use of a finished context */
|
/* avoid potential coredump caused by use of a finished context */
|
||||||
algo->init_func(pctx);
|
algo_init(algo, pctx);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
|
|
||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
|
|
||||||
#define RUBY_DIGEST_API_VERSION 2
|
#define RUBY_DIGEST_API_VERSION 3
|
||||||
|
|
||||||
typedef void (*rb_digest_hash_init_func_t)(void *);
|
typedef int (*rb_digest_hash_init_func_t)(void *);
|
||||||
typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t);
|
typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t);
|
||||||
typedef void (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
|
typedef int (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int api_version;
|
int api_version;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user