Project

General

Profile

Bug #9659 ยป 001-detect-digest-failure.patch

View differences:

ext/digest/digest.c
520 520
    Data_Get_Struct(obj, rb_digest_metadata_t, algo);
521 521

  
522 522
    switch (algo->api_version) {
523
      case 2:
523
      case 3:
524 524
        break;
525 525

  
526 526
      /*
......
548 548
    algo = get_digest_base_metadata(klass);
549 549

  
550 550
    pctx = xmalloc(algo->ctx_size);
551
    algo->init_func(pctx);
551
    if (algo->init_func(pctx) != 1) {
552
      rb_raise(rb_eRuntimeError, "Digest initialization failed.");
553
    }
552 554

  
553 555
    obj = Data_Wrap_Struct(klass, 0, xfree, pctx);
554 556

  
......
586 588

  
587 589
    Data_Get_Struct(self, void, pctx);
588 590

  
589
    algo->init_func(pctx);
591
    if (algo->init_func(pctx) != 1) {
592
      rb_raise(rb_eRuntimeError, "Digest initialization failed.");
593
    }
590 594

  
591 595
    return self;
592 596
}
......
624 628
    algo->finish_func(pctx, (unsigned char *)RSTRING_PTR(str));
625 629

  
626 630
    /* avoid potential coredump caused by use of a finished context */
627
    algo->init_func(pctx);
631
    if (algo->init_func(pctx) != 1) {
632
      rb_raise(rb_eRuntimeError, "Digest initialization failed.");
633
    }
628 634

  
629 635
    return str;
630 636
}
ext/digest/digest.h
15 15

  
16 16
#include "ruby.h"
17 17

  
18
#define RUBY_DIGEST_API_VERSION	2
18
#define RUBY_DIGEST_API_VERSION	3
19 19

  
20
typedef void (*rb_digest_hash_init_func_t)(void *);
20
typedef int (*rb_digest_hash_init_func_t)(void *);
21 21
typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t);
22
typedef void (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
22
typedef int (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
23 23

  
24 24
typedef struct {
25 25
    int api_version;