From: Oliver Kurth Date: Tue, 26 May 2020 22:32:58 +0000 (-0700) Subject: Changes to common source files not applicable to open-vm-tools. X-Git-Tag: stable-11.2.0~196 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f68d75e3d6642e2f8d7d7ef9a4cbfcab052b3be;p=thirdparty%2Fopen-vm-tools.git Changes to common source files not applicable to open-vm-tools. --- diff --git a/open-vm-tools/lib/include/random.h b/open-vm-tools/lib/include/random.h index b96c1a6e9..406520646 100644 --- a/open-vm-tools/lib/include/random.h +++ b/open-vm-tools/lib/include/random.h @@ -45,6 +45,13 @@ extern "C" { Bool Random_Crypto(size_t size, void *buffer); +/* + * The next call to Random_Crypto will fail after this function is called. + * This function does nothing in a release build. + */ + +void Random_CryptoFail(void); + /* * Research grade Mersenne Twister random number generator. * diff --git a/open-vm-tools/lib/misc/random.c b/open-vm-tools/lib/misc/random.c index 7946fae35..9f11c1d45 100644 --- a/open-vm-tools/lib/misc/random.c +++ b/open-vm-tools/lib/misc/random.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2017 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2020 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -44,6 +44,10 @@ #include "random.h" #include "util.h" +#if !defined(VMX86_RELEASE) +#include "vm_atomic.h" +#endif + #if defined(_WIN32) #if !defined(VM_WIN_UWP) @@ -182,10 +186,18 @@ RandomBytesPosix(const char *name, // IN: *----------------------------------------------------------------------------- */ +static Atomic_uint32 forceFail; + Bool Random_Crypto(size_t size, // IN: void *buffer) // OUT: { +#if !defined(VMX86_RELEASE) + if (Atomic_ReadIfEqualWrite32(&forceFail, 1, 0) == 1) { + return FALSE; + } +#endif + #if defined(_WIN32) return RandomBytesWin32(size, buffer); #else @@ -199,6 +211,34 @@ Random_Crypto(size_t size, // IN: } +/* + *----------------------------------------------------------------------------- + * + * Random_CryptoFail -- + * + * This function will cause the next call to Random_Crypto to fail. + * + * NOTE: This function does nothing in a release build. + * + * Results: + * TRUE success + * FALSE failure + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +void +Random_CryptoFail(void) +{ +#if !defined(VMX86_RELEASE) + Atomic_Write32(&forceFail, 1); +#endif +} + + /* *-----------------------------------------------------------------------------