Revision: 3772 http://trac.macosforge.org/projects/ruby/changeset/3772 Author: lsansonetti@apple.com Date: 2010-03-16 13:46:19 -0700 (Tue, 16 Mar 2010) Log Message: ----------- fixed a crasher Modified Paths: -------------- MacRuby/trunk/ext/openssl/ossl_rand.c Modified: MacRuby/trunk/ext/openssl/ossl_rand.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_rand.c 2010-03-16 20:36:23 UTC (rev 3771) +++ MacRuby/trunk/ext/openssl/ossl_rand.c 2010-03-16 20:46:19 UTC (rev 3772) @@ -98,8 +98,13 @@ VALUE str; int n = NUM2INT(len); - str = rb_str_new(0, n); - if (!RAND_bytes((unsigned char *)RSTRING_PTR(str), n)) { + if (n <= 0) { + rb_raise(rb_eArgError, "given length should be greater than 0"); + } + + str = rb_bstr_new(); + rb_bstr_resize(str, n); + if (!RAND_bytes(rb_bstr_bytes(str), n)) { ossl_raise(eRandomError, NULL); }