Skip to content

Commit aee5563

Browse files
committed
dict: Handle ENOSYS from getentropy gracefully
Should fix #854.
1 parent 6208f86 commit aee5563

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

dict.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -928,14 +928,15 @@ xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name) {
928928
#define WIN32_LEAN_AND_MEAN
929929
#include <windows.h>
930930
#include <bcrypt.h>
931-
#elif defined(HAVE_GETENTROPY)
932-
#ifdef HAVE_UNISTD_H
933-
#include <unistd.h>
934-
#endif
935-
#ifdef HAVE_SYS_RANDOM_H
936-
#include <sys/random.h>
937-
#endif
938931
#else
932+
#if defined(HAVE_GETENTROPY)
933+
#ifdef HAVE_UNISTD_H
934+
#include <unistd.h>
935+
#endif
936+
#ifdef HAVE_SYS_RANDOM_H
937+
#include <sys/random.h>
938+
#endif
939+
#endif
939940
#include <time.h>
940941
#endif
941942

@@ -965,9 +966,21 @@ xmlInitRandom(void) {
965966
"error code %lu\n", GetLastError());
966967
abort();
967968
}
968-
#elif defined(HAVE_GETENTROPY)
969+
#else
970+
int var;
971+
972+
#if defined(HAVE_GETENTROPY)
969973
while (1) {
970974
if (getentropy(globalRngState, sizeof(globalRngState)) == 0)
975+
return;
976+
977+
/*
978+
* This most likely means that libxml2 was compiled on
979+
* a system supporting certain system calls and is running
980+
* on a system that doesn't support these calls, as can
981+
* be the case on Linux.
982+
*/
983+
if (errno == ENOSYS)
971984
break;
972985

973986
if (errno != EINTR) {
@@ -976,8 +989,7 @@ xmlInitRandom(void) {
976989
abort();
977990
}
978991
}
979-
#else
980-
int var;
992+
#endif
981993

982994
globalRngState[0] =
983995
(unsigned) time(NULL) ^

0 commit comments

Comments
 (0)