Skip to content

Potentially lossy conversion in s_read_wincsp #514

@mabuchner

Description

@mabuchner

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions