From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-4.1 required=3.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id D0C691F461 for ; Tue, 14 May 2019 02:50:17 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 644C41209ED; Tue, 14 May 2019 11:50:13 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 72F341209ED for ; Tue, 14 May 2019 11:50:10 +0900 (JST) Received: by filter0094p3las1.sendgrid.net with SMTP id filter0094p3las1-2370-5CDA2CE2-2D 2019-05-14 02:50:11.046549623 +0000 UTC m=+31462.517253051 Received: from herokuapp.com (unknown [18.212.173.8]) by ismtpd0050p1iad1.sendgrid.net (SG) with ESMTP id tYdC4N8ARgOuIMH8Gu44WA for ; Tue, 14 May 2019 02:50:11.121 +0000 (UTC) Date: Tue, 14 May 2019 02:50:11 +0000 (UTC) From: shyouhei@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 68123 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15847 X-Redmine-Issue-Author: graywolf X-Redmine-Sender: shyouhei X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?jcfQDMoo=2FMGCmP3uu1SeyLQUxUPXq5PjHpHz3xSFn14f7+tICcAiu9hYeF+OEp?= =?us-ascii?Q?uIz20vGY4qOybP26aHar+oYwSPzlxzkv7rQ9FoB?= =?us-ascii?Q?Fm85EJ=2FTWEYStC48WfpeUTWJnfh1bQtQK8l1GS9?= =?us-ascii?Q?tpxLfDormkj=2FTXzGTcFjXfeCJ9Hd9azD6XECgHm?= =?us-ascii?Q?yrTpnW33vyeHgL79t6CuFsOEC09EF1mROEA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 92640 Subject: [ruby-core:92640] [Ruby trunk Bug#15847] SecureRandom#gen_random becomes private after first invocation X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15847 has been updated by shyouhei (Shyouhei Urabe). Thank you for reporting! It was my fault. have just pushed a fix. ---------------------------------------- Bug #15847: SecureRandom#gen_random becomes private after first invocation https://bugs.ruby-lang.org/issues/15847#change-78003 * Author: graywolf (Gray Wolf) * Status: Closed * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- There seems to be an issue with `SecureRandom#gen_random` becoming private after first invocation: ``` + $ /tmp/my_ruby/bin/ruby -v ruby 2.7.0dev (2019-05-13 trunk 082bbdc92e) [x86_64-linux] ``` ``` $ /tmp/my_ruby/bin/ruby \ -e 'require "securerandom"' \ -e 'SecureRandom.gen_random(1)' $ /tmp/my_ruby/bin/ruby \ -e 'require "securerandom"' \ -e 'SecureRandom.gen_random(1)' \ -e 'SecureRandom.gen_random(1)' Traceback (most recent call last): -e:3:in `
': private method `gen_random' called for SecureRandom:Module (NoMethodError) ``` This is caused by using alias since 2.5 ruby in secure random class. Both `.gen_random_openssl` and `.gen_random_urandom` are private class method. Using the `alias` on them does not remove the private property, so new `.gen_random` is private as well. Patch fixing the issue: ``` diff --git a/lib/securerandom.rb b/lib/securerandom.rb index 37835bf7df..2b0f3753b3 100644 --- a/lib/securerandom.rb +++ b/lib/securerandom.rb @@ -84,7 +84,8 @@ def gen_random(n) @rng_chooser.synchronize do class << self remove_method :gen_random - alias gen_random gen_random_openssl + alias_method(:gen_random, :gen_random_openssl) + public(:gen_random) end end return gen_random(n) @@ -93,7 +94,8 @@ class << self @rng_chooser.synchronize do class << self remove_method :gen_random - alias gen_random gen_random_urandom + alias_method(:gen_random, :gen_random_urandom) + public(:gen_random) end end return gen_random(n) ``` This bug is not present in 2.4.6. First noticed on 2.5.5. Examples in this ticket are from current trunk. -- https://bugs.ruby-lang.org/