From a5b809e994ce10d265e73f8c9d7c042e5e84d171 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 23 Aug 2019 13:00:17 +0900 Subject: Check metadata a bit more --- ext/digest/digest.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ext/digest/digest.c b/ext/digest/digest.c index 73655c5bb5..a59f880ac7 100644 --- a/ext/digest/digest.c +++ b/ext/digest/digest.c @@ -554,10 +554,22 @@ get_digest_base_metadata(VALUE klass) if (NIL_P(p)) rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby"); + if (!RB_TYPE_P(obj, T_DATA) || RTYPEDDATA_P(obj)) { + wrong: + if (p == klass) + rb_raise(rb_eTypeError, "%"PRIsVALUE"::metadata is not initialized properly", + klass); + else + rb_raise(rb_eTypeError, "%"PRIsVALUE"(%"PRIsVALUE")::metadata is not initialized properly", + klass, p); + } + #undef RUBY_UNTYPED_DATA_WARNING #define RUBY_UNTYPED_DATA_WARNING 0 Data_Get_Struct(obj, rb_digest_metadata_t, algo); + if (!algo) goto wrong; + switch (algo->api_version) { case 3: break; -- cgit v1.2.3