Skip to content

Commit

Permalink
Merge pull request #270 from itarato/bugfix/PA-missing-gc-guard
Browse files Browse the repository at this point in the history
[Bugfix] Fixing a rare bug when calling BCrypt::Engine#hash_secret - which produces nil accidentally 1 out of 500 cases
  • Loading branch information
tenderlove committed Jun 22, 2023
2 parents e402d69 + 53ec1e1 commit d4e4813
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ext/mri/bcrypt_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ static VALUE bc_salt(VALUE self, VALUE prefix, VALUE count, VALUE input) {
if(!salt) return Qnil;

str_salt = rb_str_new2(salt);

RB_GC_GUARD(prefix);
RB_GC_GUARD(input);
free(salt);

return str_salt;
Expand Down Expand Up @@ -99,6 +102,8 @@ static VALUE bc_crypt(VALUE self, VALUE key, VALUE setting) {

out = rb_str_new2(value);

RB_GC_GUARD(key);
RB_GC_GUARD(setting);
free(args.data);

return out;
Expand Down

0 comments on commit d4e4813

Please sign in to comment.