[macruby-changes] [3772] MacRuby/trunk/ext/openssl/ossl_rand.c

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 16 13:46:19 PDT 2010


Revision: 3772
          http://trac.macosforge.org/projects/ruby/changeset/3772
Author:   lsansonetti at 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);
     }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100316/c7c77a33/attachment.html>


More information about the macruby-changes mailing list