Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ext/mri/bcrypt_pbkdf_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ static VALUE cBCryptPbkdfEngine;
*/
static VALUE bc_crypt_pbkdf(VALUE self, VALUE pass, VALUE salt, VALUE keylen, VALUE rounds) {
size_t okeylen = NUM2ULONG(keylen);
if (okeylen == 0 || okeylen > 1024)
return Qnil;
u_int8_t* okey = xmalloc(okeylen);
VALUE out;

Expand All @@ -16,8 +18,10 @@ static VALUE bc_crypt_pbkdf(VALUE self, VALUE pass, VALUE salt, VALUE keylen, VA
(const u_int8_t*)StringValuePtr(salt), RSTRING_LEN(salt),
okey, okeylen,
NUM2ULONG(rounds));
if (ret < 0)
if (ret < 0) {
xfree(okey);
return Qnil;
}
out = rb_str_new((const char*)okey, okeylen);
xfree(okey);
return out;
Expand Down