]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes to common source files not applicable to open-vm-tools.
authorOliver Kurth <okurth@vmware.com>
Tue, 26 May 2020 22:32:58 +0000 (15:32 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 26 May 2020 22:32:58 +0000 (15:32 -0700)
open-vm-tools/lib/include/random.h
open-vm-tools/lib/misc/random.c

index b96c1a6e945a63f61a5ca0233cb5cb1114bc0112..4065206466c350fe0139bc047b090d7e99938733 100644 (file)
@@ -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.
  *
index 7946fae35e2bb5f4eb39e281dd431da649c29d23..9f11c1d450b37af7c5a871204c4b2dc059b4b6f6 100644 (file)
@@ -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
 #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
+}
+
+
 
 /*
  *-----------------------------------------------------------------------------