Skip to content

Commit

Permalink
libxml2: use new patch
Browse files Browse the repository at this point in the history
  • Loading branch information
gnattu committed Feb 1, 2025
1 parent 964bf4a commit f83fd1b
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 88 deletions.
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

Original file line number Diff line number Diff line change
@@ -1,48 +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..b125fa6c 100644
index 49e1c6bf..301ef61b 100644
--- a/dict.c
+++ b/dict.c
@@ -961,9 +961,19 @@ xmlInitRandom(void) {
sizeof(globalRngState),
@@ -962,9 +962,10 @@ xmlInitRandom(void) {
BCRYPT_USE_SYSTEM_PREFERRED_RNG);
if (!BCRYPT_SUCCESS(status)) {
+ int var;
fprintf(stderr, "libxml2: BCryptGenRandom failed with "
- "error code %lu\n", GetLastError());
- abort();
+ "error code %lu, using internal entropy\n", GetLastError());
+
+ 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);
+ break;
+ goto internal_entropy;
}
+ return;
#elif defined(HAVE_GETENTROPY)
while (1) {
@@ -971,9 +981,19 @@ xmlInitRandom(void) {
break;
if (getentropy(globalRngState, sizeof(globalRngState)) == 0)
@@ -972,20 +973,25 @@ xmlInitRandom(void) {

if (errno != EINTR) {
+ int var;
fprintf(stderr, "libxml2: getentropy failed with "
- "error code %d\n", errno);
- abort();
+ "error code %d, using internal entropy\n", errno);
+
+ 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);
+ break;
+ goto internal_entropy;
}
}
#else
-#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

2 changes: 1 addition & 1 deletion builder/scripts.d/25-libxml2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ffbuild_enabled() {
}

ffbuild_dockerstage() {
to_df "RUN --mount=src=${SELF},dst=/stage.sh --mount=src=patches/libxml2,dst=/patches run_stage /stage.sh"
to_df "RUN --mount=src=${SELF},dst=/stage.sh --mount=src=patches/libxml2/master,dst=/patches run_stage /stage.sh"
}

ffbuild_dockerbuild() {
Expand Down
6 changes: 2 additions & 4 deletions docker-build-win64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ popd
popd

# LIBXML2
git clone https://github.com/GNOME/libxml2.git
git clone --depth=1 https://github.com/GNOME/libxml2.git
pushd libxml2
libxml2_ver="v2.13.5"
git checkout ${libxml2_ver}
# Fallback to internal entropy when system native method failed
git apply ${SOURCE_DIR}/builder/patches/libxml2/0000-fallback-to-internal-entropy.patch
git apply ${SOURCE_DIR}/builder/patches/libxml2/master/0001-dict-Fallback-to-internal-entropy-master.patch
./autogen.sh \
--prefix=${FF_DEPS_PREFIX} \
--host=${FF_TOOLCHAIN} \
Expand Down
2 changes: 1 addition & 1 deletion docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ prepare_extra_common() {
pushd libxml2
if [[ $(lsb_release -c -s) != "focal" ]]; then
# Fallback to internal entropy when system native method failed
git apply ${SOURCE_DIR}/builder/patches/libxml2/0000-fallback-to-internal-entropy.patch
git apply ${SOURCE_DIR}/builder/patches/libxml2/v2.13.5/0001-dict-Fallback-to-internal-entropy.patch
fi
./autogen.sh \
${CROSS_OPT} \
Expand Down

This file was deleted.

7 changes: 1 addition & 6 deletions msys2/PKGBUILD/20-mingw-w64-libxml2/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ source=("https://download.gnome.org/sources/libxml2/${pkgver%.*}/${_realname}-${
0027-decoding-segfault.patch
0029-xml2-config-win-paths.patch
0030-pkgconfig-add-Cflags-private.patch
0031-apply-msvc-relocation.patch
9999-fallback-to-internal-entropy.patch)
0031-apply-msvc-relocation.patch)
sha256sums=('59912db536ab56a3996489ea0299768c7bcffe57169f0235e7f962a91f483590'
'9b61db9f5dbffa545f4b8d78422167083a8568c59bd1129f94138f936cf6fc1f'
'0391a4b267ba7251ca74ff2e98bf4c0332a14b618e8147a9341ec5617e45d9d9'
Expand Down Expand Up @@ -68,10 +67,6 @@ prepare() {
apply_patch_with_msg \
0029-xml2-config-win-paths.patch

# https://github.com/jellyfin/jellyfin/issues/13467
apply_patch_with_msg \
9999-fallback-to-internal-entropy.patch

NOCONFIGURE=1 ./autogen.sh
}

Expand Down

0 comments on commit f83fd1b

Please sign in to comment.