Skip to content
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

Potentially lossy conversion in s_read_wincsp #514

Open
mabuchner opened this issue Nov 19, 2021 · 1 comment
Open

Potentially lossy conversion in s_read_wincsp #514

mabuchner opened this issue Nov 19, 2021 · 1 comment

Comments

@mabuchner
Copy link

The s_read_wincsp function has a size_t argument n to specify the number of random bytes to generate.

static mp_err s_read_wincsp(void *p, size_t n)

This argument blindly gets converted into a DWORD

return CryptGenRandom(hProv, (DWORD)n, (BYTE *)p) == TRUE ? MP_OKAY : MP_ERR;

According to the documentation, a DWORD stores 32-bits. However, a size_t can potentially store more than 32-bits.

For example, if someone wants to generate more than 4 GB of random data on a 64-bit system, then s_read_wincsp might silently not generate the correct amount of random data.

@sjaeckel
Copy link
Member

sjaeckel commented Dec 7, 2021

a fix of this could be done when fixing #513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants