Skip to content

Instantly share code, notes, and snippets.

@akiray03
Created June 20, 2013 00:25
Show Gist options
  • Select an option

  • Save akiray03/5819343 to your computer and use it in GitHub Desktop.

Select an option

Save akiray03/5819343 to your computer and use it in GitHub Desktop.
(gdb) run t4.rb
Starting program: /home/yumiyama/work/mruby/mruby/bin/mruby t4.rb
t4.rb:6: expected String (TypeError)
"done."
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff77f1201 in EVP_MD_CTX_cleanup () from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
(gdb) bt
#0 0x00007ffff77f1201 in EVP_MD_CTX_cleanup () from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#1 0x00007ffff777265d in HMAC_CTX_cleanup () from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
#2 0x000000000045280c in lib_hmac_free (mrb=0x6ab010, ptr=0x0) at build/mrbgems/mruby-digest//src/digest.c:111
#3 0x000000000041d41b in obj_free (mrb=0x6ab010, obj=0x744140) at /home/yumiyama/work/mruby/mruby/src/gc.c:601
#4 0x000000000041e212 in mrb_free_heap (mrb=0x6ab010) at /home/yumiyama/work/mruby/mruby/src/gc.c:325
#5 0x000000000040491f in mrb_close (mrb=0x6ab010) at /home/yumiyama/work/mruby/mruby/src/state.c:150
#6 0x0000000000403fca in main (argc=<optimized out>, argv=<optimized out>) at /home/yumiyama/work/mruby/mruby/mrbgems/mruby-bin-mruby//tools/mruby/mruby.c:243
(gdb)
diff --git a/src/digest.c b/src/digest.c
index cc628ea..0e483f1 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -577,6 +577,9 @@ mrb_digest_init(mrb_state *mrb, mrb_value self)
struct mrb_md *md;
mrb_value t;
+ DATA_TYPE(self) = &mrb_md_type;
+ DATA_PTR(self) = NULL;
+
c = mrb_obj_class(mrb, self);
if (!mrb_const_defined(mrb, mrb_obj_value(c), mrb_intern(mrb, TYPESYM))) {
mrb_raise(mrb, E_NOTIMP_ERROR, "Digest::Base is an abstract class");
@@ -596,7 +599,6 @@ mrb_digest_init(mrb_state *mrb, mrb_value self)
md = (struct mrb_md *)mrb_malloc(mrb, sizeof(*md));
lib_md_init(mrb, md, mrb_fixnum(t));
DATA_PTR(self) = md;
- DATA_TYPE(self) = &mrb_md_type;
return self;
}
@@ -690,6 +692,9 @@ mrb_hmac_init(mrb_state *mrb, mrb_value self)
int keylen;
char *key;
+ DATA_TYPE(self) = &mrb_hmac_type;
+ DATA_PTR(self) = NULL;
+
mrb_get_args(mrb, "so", &key, &keylen, &digest);
t = mrb_const_get(mrb, digest, mrb_intern(mrb, TYPESYM));
if (mrb_nil_p(t)) {
@@ -704,7 +709,6 @@ mrb_hmac_init(mrb_state *mrb, mrb_value self)
hmac = (struct mrb_hmac *)mrb_malloc(mrb, sizeof(*hmac));
lib_hmac_init(mrb, hmac, mrb_fixnum(t), (unsigned char *)key, keylen);
DATA_PTR(self) = hmac;
- DATA_TYPE(self) = &mrb_hmac_type;
return self;
}
if Object.const_defined?(:RUBY_VERSION)
require 'digest/hmac'
end
begin
Digest::HMAC.hexdigest('data', nil, Digest::SHA256)
rescue => e
p e
end
p 'done.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment