delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/10/22/15:40:20

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Topher Cawlfield <tcawlfield AT gmail DOT com>
Subject: Python throws error when closing /dev/urandom
Date: Thu, 22 Oct 2009 19:35:48 +0000 (UTC)
Lines: 65
Message-ID: <loom.20091022T210419-725@post.gmane.org>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Hi,

I'm not sure if this is the right place to post such problems, but I ran into
this problem when trying to use the paramiko library with python 2.5.2 in Cygwin.

Ultimately the problem is that an IOError is generated when opening
/dev/urandom, reading some bytes from it (doesn't seem to matter how much),
and closing the file.  If you don't read from the file there is no error upon 
closing.

$ python
Python 2.5.2 (r252:60911, Dec  2 2008, 09:26:14) 
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
.>>> f = open("/dev/urandom")
.>>> f.close()

Note: no problem just opening and closing the special file.  But:

.>>> f = open("/dev/urandom")
.>>> f.read(8)
'\xf9"\xb7\'E\xf8Q\xa0'
.>>> f.close()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 0] Error
.>>> 

This problem manifests itself when trying to use the paramiko library in
any way:
.>>> import paramiko
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "__init__.py", line 69, in <module>
  File "transport.py", line 32, in <module>
  File "util.py", line 31, in <module>
  File "common.py", line 101, in <module>
  File "rng.py", line 69, in __init__
  File "randpool.py", line 87, in __init__
  File "randpool.py", line 120, in _randomize
IOError: [Errno 0] Error

This error ultimately comes from
/usr/lib/python2.5/site-packages/Crypto/Util/randpool.py, line 118, which I
believe I got from python-crypto 2.0.1-1.

This bug was previously noticed at least a year ago:
http://www.cygwin.com/ml/cygwin/2008-09/msg00561.html (and others)


The suggested work-around, for users of python-crypto, was to change the line
just below this in randpool.py from:
            except IOError, (num, msg):
                if num!=2: raise IOError, (num, msg)
to
            except IOError, (num, msg):
                if num!=2 and num!=0: raise IOError, (num, msg)

There was some concern about the validity of this fix but it seems to me that
random data is being pulled from /dev/urandom just fine.  But still it would be
nice to attack this problem at the root.

It seems likely that this problem is not reproduced on all systems since, after
all, paramiko is distributed in Cygwin and yet I cannot even import the module.
I'm not sure what else I should detail about my system.  It's running Vista SP1.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019