Ruby bug reading from /dev/urandom after failed require?

Discussion in 'Ruby' started by Mike Boone, Dec 22, 2007.

  1. Mike Boone

    Mike Boone Guest

    I've been trying to track down a bug that surfaced when trying to
    generate a Rails 2.0.2 app in Cygwin. Reading from /dev/urandom fails
    with "No such file or directory - /dev/urandom" if a failed require
    has been made previously.

    The Rails code looks OK, so I thought it might be Cygwin. I came up
    with a simple snippet that fails in Cygwin (see below). Corinna
    Vinschen over at Cygwin ran strace on it and thought it might be a
    Ruby bug...see her thoughts here:
    http://cygwin.com/ml/cygwin/2007-12/msg00502.html

    I'm not well versed on the low level strace stuff, but I thought I'd
    try to see this through. I'd appreciate any comments from someone
    knowledgeable about the Ruby source.

    Demonstration code:
    ----------------------------
    # Test failure of reading /dev/urandom after failed require

    # this method is from the Rails' source secret_key_generator.rb
    def generate_secret_with_urandom
    return File.read("/dev/urandom", 64).unpack("H*")[0]
    end

    cause_failure = true

    begin
    require 'nonexistent_file'
    rescue LoadError
    puts '' unless cause_failure
    end

    puts generate_secret_with_urandom
    ----------------------------

    Thanks,
    Mike Boone
    http://boonedocks.net/mike/
     
    Mike Boone, Dec 22, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Grzegorz Smith

    trying to get hash from os.urandom

    Grzegorz Smith, Jan 23, 2006, in forum: Python
    Replies:
    2
    Views:
    967
    Robert Kern
    Jan 23, 2006
  2. Ron Peterson

    /dev/urandom vs. /dev/random

    Ron Peterson, Jan 7, 2005, in forum: C Programming
    Replies:
    21
    Views:
    1,612
    Keith Thompson
    Jan 13, 2005
  3. gert
    Replies:
    7
    Views:
    645
  4. AC
    Replies:
    0
    Views:
    192
  5. Michele Dondi
    Replies:
    1
    Views:
    167
    Anno Siegel
    Feb 22, 2004
Loading...

Share This Page