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=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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 3126D1F461 for ; Mon, 26 Aug 2019 15:14:05 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 8EF64120999; Tue, 27 Aug 2019 00:13:57 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id CE91A120999 for ; Tue, 27 Aug 2019 00:13:54 +0900 (JST) Received: by filter0101p3las1.sendgrid.net with SMTP id filter0101p3las1-30709-5D63F734-5 2019-08-26 15:13:56.109893983 +0000 UTC m=+766574.980200390 Received: from herokuapp.com (unknown [3.82.112.209]) by ismtpd0049p1mdw1.sendgrid.net (SG) with ESMTP id _Za3OtvNRWqScUYKhlKPbQ for ; Mon, 26 Aug 2019 15:13:55.974 +0000 (UTC) Date: Mon, 26 Aug 2019 15:13:56 +0000 (UTC) From: usa@garbagecollect.jp Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70123 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15847 X-Redmine-Issue-Author: graywolf X-Redmine-Sender: usa 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?9Ij0W+xF+66shKwcOf8RvdqxJGkEJjaCZuueI4cieuDUxMJdGrArW2OHKQ1NLw?= =?us-ascii?Q?oed0agHZQzL7r=2FZ4fdPFwap6WiX+Vc1picX2n1S?= =?us-ascii?Q?rbHpNAGh8GDbib060Q7FqG6QdOdK8D9mfvIOtbP?= =?us-ascii?Q?URdZbe7tZmdJz4ARCBogdmDObOxoIGwBh+70Bcw?= =?us-ascii?Q?R4ivf9oPOMaRWy=2FMOVK0gXiW331BexVk0JA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 94571 Subject: [ruby-core:94571] [Ruby master 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 usa (Usaku NAKAMURA). Backport changed from 2.4: DONTNEED, 2.5: REQUIRED, 2.6: DONE to 2.4: DONTNEED, 2.5: DONE, 2.6: DONE ruby_2_5 r67762 merged revision(s) 5bab1304af25a843728dbcd2f3594913740aecb0. ---------------------------------------- Bug #15847: SecureRandom#gen_random becomes private after first invocation https://bugs.ruby-lang.org/issues/15847#change-81029 * 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: DONTNEED, 2.5: DONE, 2.6: DONE ---------------------------------------- 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/