[PATCH v5 0/1] MR10187: bcryptprimitives: Ensure ProcessPrng fills the whole buffer
[`ProcessPrng`](https://learn.microsoft.com/en-us/windows/win32/seccng/processprng) takes a `SIZE_T` argument for its length whereas [`RtlGenRandom`](https://learn.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtl...) takes a `ULONG`, which may be smaller. -- v5: bcryptprimitives: Ensure ProcessPrng fills the whole buffer https://gitlab.winehq.org/wine/wine/-/merge_requests/10187
From: Chris Denton <chris@chrisdenton.dev> ProcessPrng takes a SIZE_T argument for its length whereas RtlGenRandom takes a ULONG, which may be smaller. --- dlls/bcryptprimitives/main.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dlls/bcryptprimitives/main.c b/dlls/bcryptprimitives/main.c index 6562d672389..689f213d112 100644 --- a/dlls/bcryptprimitives/main.c +++ b/dlls/bcryptprimitives/main.c @@ -17,11 +17,26 @@ */ #include <stdarg.h> +#include <limits.h> + #include "windef.h" #include "winbase.h" #include "ntsecapi.h" BOOL WINAPI ProcessPrng(BYTE *data, SIZE_T size) { - return RtlGenRandom(data, size); + while (size) + { + SIZE_T len = min( size, (SIZE_T)ULONG_MAX ); + + if (!RtlGenRandom( data, len )) + { + /* This should be unreachable */ + return FALSE; + } + + data += len; + size -= len; + } + return TRUE; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10187
participants (2)
-
Chris Denton -
Christopher Denton (@cdenton)