Author martin.panter
Recipients haypo, martin.panter, virtuald
Date 2017-01-08.21:20:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1483910402.86.0.327009779042.issue29208@psf.upfronthosting.co.za>
In-reply-to
Content
It looks like the logic for handling an error seeding from urandom is reversed: <https://hg.python.org/cpython/rev/45fc0c83ed42#l6.66>. Random_seed_urandom() actually returns -1 if is an exception set, and 0 if it was successful.

The result would be a normal working urandom setup ignores urandom and seeds from the time and PID. Not a big deal, since the old code always seeded from a (lower resolution) time anyway. But if urandom failed, we get the SystemError.

The fix should be simple, in Modules/_randommodule.c change the random_seed() function to read

if (arg == NULL || arg == Py_None) {
    if (random_seed_urandom(self) < 0) { // was >= 0!
        PyErr_Clear();
        
        /* Reading system entropy failed, fall back on the worst entropy:
           use the current time and process identifier. */
        random_seed_time_pid(self);
    }
    Py_RETURN_NONE;
}
History
Date User Action Args
2017-01-08 21:20:02martin.pantersetrecipients: + martin.panter, haypo, virtuald
2017-01-08 21:20:02martin.pantersetmessageid: <1483910402.86.0.327009779042.issue29208@psf.upfronthosting.co.za>
2017-01-08 21:20:02martin.panterlinkissue29208 messages
2017-01-08 21:20:02martin.pantercreate