xref: /aosp_15_r20/external/cronet/third_party/libxml/chromium/remove-getentropy.patch (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1This patch removes calls to getentropy() and BCryptGetRandom() because they
2aren't implemented or supported on certain platforms based on the trybot
3results I saw. I will try upstreaming a configure script flag soon to replace
4this patch file. This patch is safe because it reverts the random number
5generation behavior before a recent libxml upstream patch.
6
7diff --git a/dict.c b/dict.c
8index 5c9f3aa2..7a492895 100644
9--- a/dict.c
10+++ b/dict.c
11@@ -24,14 +24,10 @@
12 #include <stdlib.h>
13 #include <string.h>
14 #include <time.h>
15-#ifdef HAVE_SYS_RANDOM_H
16-#include <sys/random.h>
17-#endif
18
19 #ifdef _WIN32
20 #define WIN32_LEAN_AND_MEAN
21 #include <windows.h>
22-#include <bcrypt.h>
23 #endif
24
25 #include "private/dict.h"
26@@ -926,29 +922,6 @@ xmlInitRandom(void) {
27     xmlInitMutex(&xmlRngMutex);
28
29     {
30-#ifdef _WIN32
31-        NTSTATUS status;
32-
33-        status = BCryptGenRandom(NULL, (unsigned char *) globalRngState,
34-                                 sizeof(globalRngState),
35-                                 BCRYPT_USE_SYSTEM_PREFERRED_RNG);
36-        if (!BCRYPT_SUCCESS(status)) {
37-            fprintf(stderr, "libxml2: BCryptGenRandom failed with "
38-                    "error code %lu\n", GetLastError());
39-            abort();
40-        }
41-#elif defined(HAVE_GETENTROPY)
42-        while (1) {
43-            if (getentropy(globalRngState, sizeof(globalRngState)) == 0)
44-                break;
45-
46-            if (errno != EINTR) {
47-                fprintf(stderr, "libxml2: getentropy failed with "
48-                        "error code %d\n", errno);
49-                abort();
50-            }
51-        }
52-#else
53         int var;
54
55         globalRngState[0] =
56@@ -957,7 +930,6 @@ xmlInitRandom(void) {
57         globalRngState[1] =
58                 HASH_ROL((unsigned) ((size_t) &xmlRngMutex & 0xFFFFFFFF), 16) ^
59                 HASH_ROL((unsigned) ((size_t) &var & 0xFFFFFFFF), 24);
60-#endif
61     }
62 }
63
64