[前][次][番号順一覧][スレッド一覧]

ruby-changes:24909

From: shirosaki <ko1@a...>
Date: Thu, 13 Sep 2012 22:01:32 +0900 (JST)
Subject: [ruby-changes:24909] shirosaki:r36961 (trunk): lib/securerandom.rb: fix errors on Windows

shirosaki	2012-09-13 22:01:23 +0900 (Thu, 13 Sep 2012)

  New Revision: 36961

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36961

  Log:
    lib/securerandom.rb: fix errors on Windows
    
    * lib/securerandom.rb (SecureRandom.random_bytes):
      Use 64bit value as pointer for Windows x64 to fix SystemCallError.
    
    * lib/securerandom.rb (SecureRandom.lastWin32ErrorMessage):
      Set proper encoding to avoid invalid byte sequence error.
      [ruby-core:47451] [Bug #6990]

  Modified files:
    trunk/ChangeLog
    trunk/lib/securerandom.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36960)
+++ ChangeLog	(revision 36961)
@@ -1,3 +1,12 @@
+Thu Sep 13 21:40:49 2012  Hiroshi Shirosaki  <h.shirosaki@g...>
+
+	* lib/securerandom.rb (SecureRandom.random_bytes):
+	  Use 64bit value as pointer for Windows x64 to fix SystemCallError.
+
+	* lib/securerandom.rb (SecureRandom.lastWin32ErrorMessage):
+	  Set proper encoding to avoid invalid byte sequence error.
+	  [ruby-core:47451] [Bug #6990]
+
 Thu Sep 13 11:20:00 2012  Zachary Scott  <zzak@r...>
 
 	* lib/optparse.rb: Remove unreachable email address from documentation
Index: lib/securerandom.rb
===================================================================
--- lib/securerandom.rb	(revision 36960)
+++ lib/securerandom.rb	(revision 36961)
@@ -94,16 +94,17 @@
         require 'Win32API'
 
         crypt_acquire_context = Win32API.new("advapi32", "CryptAcquireContext", 'PPPII', 'L')
-        @crypt_gen_random = Win32API.new("advapi32", "CryptGenRandom", 'LIP', 'L')
+        @crypt_gen_random = Win32API.new("advapi32", "CryptGenRandom", 'VIP', 'L')
 
-        hProvStr = " " * 4
+        hProvStr = " " * DL::SIZEOF_VOIDP
         prov_rsa_full = 1
         crypt_verifycontext = 0xF0000000
 
         if crypt_acquire_context.call(hProvStr, nil, nil, prov_rsa_full, crypt_verifycontext) == 0
           raise SystemCallError, "CryptAcquireContext failed: #{lastWin32ErrorMessage}"
         end
-        @hProv, = hProvStr.unpack('L')
+        type = DL::SIZEOF_VOIDP == DL::SIZEOF_LONG_LONG ? 'q' : 'l'
+        @hProv, = hProvStr.unpack(type)
 
         @has_win32 = true
       rescue LoadError
@@ -260,6 +261,6 @@
     code = get_last_error.call
     msg = "\0" * 1024
     len = format_message.call(format_message_ignore_inserts + format_message_from_system, 0, code, 0, msg, 1024, nil, nil, nil, nil, nil, nil, nil, nil)
-    msg[0, len].tr("\r", '').chomp
+    msg[0, len].force_encoding("filesystem").tr("\r", '').chomp
   end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]