New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyurandom() fails if user does not have an entropy device #79308
Comments
Because of [reasons], I installed a FreeBSD and recompiled it to provide a minimalist kernel. Thus, it does not have the entropy devices /dev/urandom and /dev/random It is a FreeBSD-10-0 running in a Hyper-V virutalization platform. I kinda recompiled python-3.7.1 from the source code to get my own version of python running, but I got stuck in this part. So looking at the Modules/bootstrap_hash.c file I do not see the code of pyurandom() falling back to a something silly. Plus, there is a problem that happens only in Unix at least in this version of python. Looking at the code of the same file. we can see: static int pyurandom(...)
{
...
int res
...
if (res < 0){
return -1
}
if (res == 1){
return 0
}
...
} I am sorry for the laziness but I believe my point is clear. The thing is. If the random function returns 0 it will return 0 but if it returns 1 it will also return 0. In other words, the number 1 is out of the scope of the random numbers. It is a small prejudice for the random function, but it is not mathematically right. This issue with the number 1, does not happen if the user does not have /dev/random (But it still needs /dev/urandom) |
My reading of the code is that res is a success/failure indicator, and the random number is returned in the buffer (first arg). |
The code works as expected. Thanks for closing the issue @iritkatriel. I modified Python locally to make sure that opening /dev/urandom fails: I replaced /dev/urandom with /xdev/urandom. I also removed the code calling py_getrandom() or py_getentropy().
With my changes, Python fails at startup with a fatal error as expected:
Your comment is about py_getrandom() / py_getentropy() API which has a different API than pyurandom(). pyurandom() returns 0 on success:
py_getrandom() and py_getentropy() returns 1 on success:
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: