-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libxml2: fallback to internal entropy (#531)
* libxml2: fallback to internal entropy
- Loading branch information
Showing
5 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
builder/patches/libxml2/master/0001-dict-Fallback-to-internal-entropy-master.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
From fafdb8d58fd001bd167608e9b23d1a3a1f252281 Mon Sep 17 00:00:00 2001 | ||
From: nyanmisaka <[email protected]> | ||
Date: Sat, 1 Feb 2025 15:08:12 +0800 | ||
Subject: [PATCH] dict: Fallback to internal entropy | ||
|
||
Signed-off-by: nyanmisaka <[email protected]> | ||
--- | ||
dict.c | 42 +++++++++++++++++++++++++++--------------- | ||
1 file changed, 27 insertions(+), 15 deletions(-) | ||
|
||
diff --git a/dict.c b/dict.c | ||
index ccd8b54..f4010e4 100644 | ||
--- a/dict.c | ||
+++ b/dict.c | ||
@@ -957,28 +957,40 @@ xmlInitRandom(void) { | ||
status = BCryptGenRandom(NULL, (unsigned char *) globalRngState, | ||
sizeof(globalRngState), | ||
BCRYPT_USE_SYSTEM_PREFERRED_RNG); | ||
- if (!BCRYPT_SUCCESS(status)) | ||
- xmlAbort("libxml2: BCryptGenRandom failed with error code %lu\n", | ||
- GetLastError()); | ||
+ if (!BCRYPT_SUCCESS(status)) { | ||
+ xmlPrintErrorMessage("libxml2: BCryptGenRandom failed with " | ||
+ "error code %lu, using internal entropy\n", | ||
+ GetLastError()); | ||
+ goto internal_entropy; | ||
+ } | ||
+ return; | ||
#elif HAVE_DECL_GETENTROPY | ||
while (1) { | ||
if (getentropy(globalRngState, sizeof(globalRngState)) == 0) | ||
break; | ||
|
||
- if (errno != EINTR) | ||
- xmlAbort("libxml2: getentropy failed with error code %d\n", | ||
- errno); | ||
+ if (errno != EINTR) { | ||
+ xmlPrintErrorMessage("libxml2: getentropy failed with " | ||
+ "error code %d, using internal entropy\n", | ||
+ errno); | ||
+ goto internal_entropy; | ||
+ } | ||
} | ||
-#else | ||
- int var; | ||
- | ||
- globalRngState[0] = | ||
- (unsigned) time(NULL) ^ | ||
- HASH_ROL((unsigned) ((size_t) &xmlInitRandom & 0xFFFFFFFF), 8); | ||
- globalRngState[1] = | ||
- HASH_ROL((unsigned) ((size_t) &xmlRngMutex & 0xFFFFFFFF), 16) ^ | ||
- HASH_ROL((unsigned) ((size_t) &var & 0xFFFFFFFF), 24); | ||
+ return; | ||
#endif | ||
+internal_entropy: | ||
+ { | ||
+ int var; | ||
+ | ||
+ memset(globalRngState, 0, sizeof(globalRngState)); | ||
+ | ||
+ globalRngState[0] = | ||
+ (unsigned) time(NULL) ^ | ||
+ HASH_ROL((unsigned) ((size_t) &xmlInitRandom & 0xFFFFFFFF), 8); | ||
+ globalRngState[1] = | ||
+ HASH_ROL((unsigned) ((size_t) &xmlRngMutex & 0xFFFFFFFF), 16) ^ | ||
+ HASH_ROL((unsigned) ((size_t) &var & 0xFFFFFFFF), 24); | ||
+ } | ||
} | ||
} | ||
|
||
-- | ||
2.34.1 | ||
|
67 changes: 67 additions & 0 deletions
67
builder/patches/libxml2/v2.13.5/0001-dict-Fallback-to-internal-entropy.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
From 09b9b54c88cb45e5892ca2b5e0f4e4e33877cc4a Mon Sep 17 00:00:00 2001 | ||
From: nyanmisaka <[email protected]> | ||
Date: Sat, 1 Feb 2025 15:19:30 +0800 | ||
Subject: [PATCH] dict: Fallback to internal entropy | ||
|
||
Signed-off-by: nyanmisaka <[email protected]> | ||
--- | ||
dict.c | 32 +++++++++++++++++++------------- | ||
1 file changed, 19 insertions(+), 13 deletions(-) | ||
|
||
diff --git a/dict.c b/dict.c | ||
index 49e1c6bf..301ef61b 100644 | ||
--- a/dict.c | ||
+++ b/dict.c | ||
@@ -962,9 +962,10 @@ xmlInitRandom(void) { | ||
BCRYPT_USE_SYSTEM_PREFERRED_RNG); | ||
if (!BCRYPT_SUCCESS(status)) { | ||
fprintf(stderr, "libxml2: BCryptGenRandom failed with " | ||
- "error code %lu\n", GetLastError()); | ||
- abort(); | ||
+ "error code %lu, using internal entropy\n", GetLastError()); | ||
+ goto internal_entropy; | ||
} | ||
+ return; | ||
#elif defined(HAVE_GETENTROPY) | ||
while (1) { | ||
if (getentropy(globalRngState, sizeof(globalRngState)) == 0) | ||
@@ -972,20 +973,25 @@ xmlInitRandom(void) { | ||
|
||
if (errno != EINTR) { | ||
fprintf(stderr, "libxml2: getentropy failed with " | ||
- "error code %d\n", errno); | ||
- abort(); | ||
+ "error code %d, using internal entropy\n", errno); | ||
+ goto internal_entropy; | ||
} | ||
} | ||
-#else | ||
- int var; | ||
- | ||
- globalRngState[0] = | ||
- (unsigned) time(NULL) ^ | ||
- HASH_ROL((unsigned) ((size_t) &xmlInitRandom & 0xFFFFFFFF), 8); | ||
- globalRngState[1] = | ||
- HASH_ROL((unsigned) ((size_t) &xmlRngMutex & 0xFFFFFFFF), 16) ^ | ||
- HASH_ROL((unsigned) ((size_t) &var & 0xFFFFFFFF), 24); | ||
+ return; | ||
#endif | ||
+internal_entropy: | ||
+ { | ||
+ int var; | ||
+ | ||
+ memset(globalRngState, 0, sizeof(globalRngState)); | ||
+ | ||
+ globalRngState[0] = | ||
+ (unsigned) time(NULL) ^ | ||
+ HASH_ROL((unsigned) ((size_t) &xmlInitRandom & 0xFFFFFFFF), 8); | ||
+ globalRngState[1] = | ||
+ HASH_ROL((unsigned) ((size_t) &xmlRngMutex & 0xFFFFFFFF), 16) ^ | ||
+ HASH_ROL((unsigned) ((size_t) &var & 0xFFFFFFFF), 24); | ||
+ } | ||
} | ||
} | ||
|
||
-- | ||
2.34.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters