[PATCH 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. -- 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 | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/dlls/bcryptprimitives/main.c b/dlls/bcryptprimitives/main.c index 6562d672389..267acdaac16 100644 --- a/dlls/bcryptprimitives/main.c +++ b/dlls/bcryptprimitives/main.c @@ -16,12 +16,31 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#include <assert.h> #include <stdarg.h> +#include <limits.h> + #include "windef.h" #include "winbase.h" #include "ntsecapi.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(bcrypt); BOOL WINAPI ProcessPrng(BYTE *data, SIZE_T size) { - return RtlGenRandom(data, size); + while (size) + { + SIZE_T len = min( size, 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)