git ssb

0+

dangerousbeans / %aPBe2k3ugtjBr4rrsU1…



Commit 3b8e2f23b4ce58d899a4fd628ba6837054d85614

Fix for segfaults on the various ways Ruby has empty strings.

Thanks to Mike Pomraning for the patch.
Coda Hale committed on 3/10/2009, 3:36:19 AM
Parent: 95d6f418506621edfc65822a03209384c4e03b2b

Files changed

ext/bcrypt_ext.cchanged
spec/bcrypt/password_spec.rbchanged
ext/bcrypt_ext.cView
@@ -15,9 +15,10 @@
1515
1616 /* Given a secret and a salt, generates a salted hash (which you can then store safely).
1717 */
1818 static VALUE bc_crypt(VALUE self, VALUE key, VALUE salt) {
19- return rb_str_new2((char *)bcrypt(RSTRING_PTR(key), (char *)RSTRING_PTR(salt)));
19+ const char * safeguarded = RSTRING_PTR(key) ? RSTRING_PTR(key) : "";
20+ return rb_str_new2((char *)bcrypt(safeguarded, (char *)RSTRING_PTR(salt)));
2021 }
2122
2223 /* Create the BCrypt and BCrypt::Internals modules, and populate them with methods. */
2324 void Init_bcrypt_ext(){
spec/bcrypt/password_spec.rbView
@@ -19,8 +19,14 @@
1919 lambda { BCrypt::Password.create(nil) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
2020 lambda { BCrypt::Password.create({:woo => "yeah"}) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
2121 lambda { BCrypt::Password.create(false) }.should_not raise_error(BCrypt::Errors::InvalidSecret)
2222 end
23+
24+ specify "should tolerate empty string secrets" do
25+ lambda { BCrypt::Password.create( "\n".chop ) }.should_not raise_error
26+ lambda { BCrypt::Password.create( "" ) }.should_not raise_error
27+ lambda { BCrypt::Password.create( String.new ) }.should_not raise_error
28+ end
2329 end
2430
2531 context "Reading a hashed password" do
2632 setup do

Built with git-ssb-web