components/libxml2/patches/19.CVE-2012-0841.patch
author Kevin Crowe <Kevin.Crowe@oracle.com>
Thu, 14 Jun 2012 06:17:08 -0700
changeset 868 bb69a554cd60
permissions -rw-r--r--
7008726 Problem with library/libxml 7171310 Problem with library/libxml 7150804 Problem with library/libxml
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
868
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     1
This patch copied/pasted from this link:
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     2
http://git.gnome.org/browse/libxml2/patch/?id=8973d58b7498fa5100a876815476b81fd1a2412a
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     3
----------------------------------------------------------------------
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     4
From 8973d58b7498fa5100a876815476b81fd1a2412a Mon Sep 17 00:00:00 2001
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     5
From: Daniel Veillard <[email protected]>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     6
Date: Sat, 04 Feb 2012 11:07:44 +0000
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     7
Subject: Add hash randomization to hash and dict structures
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     8
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
     9
Following http://www.ocert.org/advisories/ocert-2011-003.html
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    10
it seems that having hash randomization might be a good idea
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    11
when using XML with untrusted data
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    12
* configure.in: lookup for rand, srand and time
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    13
* dict.c: add randomization to dictionaries hash tables
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    14
* hash.c: add randomization to normal hash tables
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    15
---
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    16
diff --git a/configure.in b/configure.in
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    17
index fa80375..828b66a 100644
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    18
--- a/configure.in
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    19
+++ b/configure.in
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    20
@@ -512,6 +512,7 @@ AC_CHECK_FUNCS(strdup strndup strerror)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    21
 AC_CHECK_FUNCS(finite isnand fp_class class fpclass)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    22
 AC_CHECK_FUNCS(strftime localtime gettimeofday ftime)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    23
 AC_CHECK_FUNCS(stat _stat signal)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    24
+AC_CHECK_FUNCS(rand srand time)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    25
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    26
 dnl Checking the standard string functions availability
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    27
 AC_CHECK_FUNCS(printf sprintf fprintf snprintf vfprintf vsprintf vsnprintf sscanf,,
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    28
diff --git a/dict.c b/dict.c
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    29
index 3eff231..ae4966b 100644
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    30
--- a/dict.c
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    31
+++ b/dict.c
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    32
@@ -2,7 +2,7 @@
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    33
  * dict.c: dictionary of reusable strings, just used to avoid allocation
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    34
  *         and freeing operations.
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    35
  *
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    36
- * Copyright (C) 2003 Daniel Veillard.
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    37
+ * Copyright (C) 2003-2012 Daniel Veillard.
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    38
  *
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    39
  * Permission to use, copy, modify, and distribute this software for any
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    40
  * purpose with or without fee is hereby granted, provided that the above
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    41
@@ -19,6 +19,28 @@
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    42
 #define IN_LIBXML
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    43
 #include "libxml.h"
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    44
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    45
+#ifdef HAVE_STDLIB_H
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    46
+#include <stdlib.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    47
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    48
+#ifdef HAVE_TIME_H
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    49
+#include <time.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    50
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    51
+
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    52
+/*
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    53
+ * Following http://www.ocert.org/advisories/ocert-2011-003.html
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    54
+ * it seems that having hash randomization might be a good idea
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    55
+ * when using XML with untrusted data
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    56
+ * Note1: that it works correctly only if compiled with WITH_BIG_KEY
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    57
+ *  which is the default.
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    58
+ * Note2: the fast function used for a small dict won't protect very
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    59
+ *  well but since the attack is based on growing a very big hash
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    60
+ *  list we will use the BigKey algo as soon as the hash size grows
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    61
+ *  over MIN_DICT_SIZE so this actually works
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    62
+ */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    63
+#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(HAVE_TIME)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    64
+#define DICT_RANDOMIZATION
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    65
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    66
+
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    67
 #include <string.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    68
 #ifdef HAVE_STDINT_H
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    69
 #include <stdint.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    70
@@ -44,23 +66,23 @@ typedef unsigned __int32 uint32_t;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    71
 #define WITH_BIG_KEY
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    72
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    73
 #ifdef WITH_BIG_KEY
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    74
-#define xmlDictComputeKey(dict, name, len)			\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    75
-    (((dict)->size == MIN_DICT_SIZE) ?				\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    76
-     xmlDictComputeFastKey(name, len) :				\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    77
-     xmlDictComputeBigKey(name, len))
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    78
-
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    79
-#define xmlDictComputeQKey(dict, prefix, plen, name, len)	\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    80
-    (((prefix) == NULL) ?					\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    81
-      (xmlDictComputeKey(dict, name, len)) :			\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    82
-      (((dict)->size == MIN_DICT_SIZE) ?			\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    83
-       xmlDictComputeFastQKey(prefix, plen, name, len) :	\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    84
-       xmlDictComputeBigQKey(prefix, plen, name, len)))
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    85
+#define xmlDictComputeKey(dict, name, len)                              \
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    86
+    (((dict)->size == MIN_DICT_SIZE) ?                                  \
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    87
+     xmlDictComputeFastKey(name, len, (dict)->seed) :                   \
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    88
+     xmlDictComputeBigKey(name, len, (dict)->seed))
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    89
+
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    90
+#define xmlDictComputeQKey(dict, prefix, plen, name, len)               \
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    91
+    (((prefix) == NULL) ?                                               \
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    92
+      (xmlDictComputeKey(dict, name, len)) :                             \
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    93
+      (((dict)->size == MIN_DICT_SIZE) ?                                \
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    94
+       xmlDictComputeFastQKey(prefix, plen, name, len, (dict)->seed) :	\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    95
+       xmlDictComputeBigQKey(prefix, plen, name, len, (dict)->seed)))
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    96
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    97
 #else /* !WITH_BIG_KEY */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    98
-#define xmlDictComputeKey(dict, name, len)			\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
    99
-        xmlDictComputeFastKey(name, len)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   100
-#define xmlDictComputeQKey(dict, prefix, plen, name, len)	\
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   101
-        xmlDictComputeFastQKey(prefix, plen, name, len)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   102
+#define xmlDictComputeKey(dict, name, len)                              \
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   103
+        xmlDictComputeFastKey(name, len, (dict)->seed)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   104
+#define xmlDictComputeQKey(dict, prefix, plen, name, len)               \
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   105
+        xmlDictComputeFastQKey(prefix, plen, name, len, (dict)->seed)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   106
 #endif /* WITH_BIG_KEY */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   107
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   108
 /*
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   109
@@ -98,6 +120,8 @@ struct _xmlDict {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   110
     xmlDictStringsPtr strings;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   111
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   112
     struct _xmlDict *subdict;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   113
+    /* used for randomization */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   114
+    int seed;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   115
 };
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   116
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   117
 /*
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   118
@@ -125,6 +149,9 @@ static int xmlInitializeDict(void) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   119
     if ((xmlDictMutex = xmlNewRMutex()) == NULL)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   120
         return(0);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   121
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   122
+#ifdef DICT_RANDOMIZATION
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   123
+    srand(time(NULL));
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   124
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   125
     xmlDictInitialized = 1;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   126
     return(1);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   127
 }
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   128
@@ -277,13 +304,13 @@ found_pool:
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   129
  */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   130
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   131
 static uint32_t
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   132
-xmlDictComputeBigKey(const xmlChar* data, int namelen) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   133
+xmlDictComputeBigKey(const xmlChar* data, int namelen, int seed) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   134
     uint32_t hash;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   135
     int i;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   136
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   137
     if (namelen <= 0 || data == NULL) return(0);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   138
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   139
-    hash = 0;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   140
+    hash = seed;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   141
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   142
     for (i = 0;i < namelen; i++) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   143
         hash += data[i];
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   144
@@ -310,12 +337,12 @@ xmlDictComputeBigKey(const xmlChar* data, int namelen) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   145
  */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   146
 static unsigned long
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   147
 xmlDictComputeBigQKey(const xmlChar *prefix, int plen,
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   148
-                      const xmlChar *name, int len)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   149
+                      const xmlChar *name, int len, int seed)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   150
 {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   151
     uint32_t hash;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   152
     int i;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   153
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   154
-    hash = 0;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   155
+    hash = seed;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   156
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   157
     for (i = 0;i < plen; i++) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   158
         hash += prefix[i];
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   159
@@ -346,8 +373,8 @@ xmlDictComputeBigQKey(const xmlChar *prefix, int plen,
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   160
  * for low hash table fill.
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   161
  */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   162
 static unsigned long
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   163
-xmlDictComputeFastKey(const xmlChar *name, int namelen) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   164
-    unsigned long value = 0L;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   165
+xmlDictComputeFastKey(const xmlChar *name, int namelen, int seed) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   166
+    unsigned long value = seed;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   167
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   168
     if (name == NULL) return(0);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   169
     value = *name;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   170
@@ -381,9 +408,9 @@ xmlDictComputeFastKey(const xmlChar *name, int namelen) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   171
  */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   172
 static unsigned long
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   173
 xmlDictComputeFastQKey(const xmlChar *prefix, int plen,
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   174
-                       const xmlChar *name, int len)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   175
+                       const xmlChar *name, int len, int seed)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   176
 {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   177
-    unsigned long value = 0L;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   178
+    unsigned long value = (unsigned long) seed;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   179
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   180
     if (plen == 0)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   181
 	value += 30 * (unsigned long) ':';
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   182
@@ -460,6 +487,11 @@ xmlDictCreate(void) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   183
 	dict->subdict = NULL;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   184
         if (dict->dict) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   185
 	    memset(dict->dict, 0, MIN_DICT_SIZE * sizeof(xmlDictEntry));
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   186
+#ifdef DICT_RANDOMIZATION
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   187
+            dict->seed = rand();
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   188
+#else
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   189
+            dict->seed = 0;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   190
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   191
 	    return(dict);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   192
         }
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   193
         xmlFree(dict);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   194
@@ -486,6 +518,7 @@ xmlDictCreateSub(xmlDictPtr sub) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   195
 #ifdef DICT_DEBUG_PATTERNS
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   196
         fprintf(stderr, "R");
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   197
 #endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   198
+        dict->seed = sub->seed;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   199
         dict->subdict = sub;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   200
 	xmlDictReference(dict->subdict);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   201
     }
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   202
diff --git a/hash.c b/hash.c
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   203
index b78bc2d..fe1424f 100644
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   204
--- a/hash.c
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   205
+++ b/hash.c
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   206
@@ -3,7 +3,7 @@
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   207
  *
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   208
  * Reference: Your favorite introductory book on algorithms
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   209
  *
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   210
- * Copyright (C) 2000 Bjorn Reese and Daniel Veillard.
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   211
+ * Copyright (C) 2000,2012 Bjorn Reese and Daniel Veillard.
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   212
  *
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   213
  * Permission to use, copy, modify, and distribute this software for any
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   214
  * purpose with or without fee is hereby granted, provided that the above
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   215
@@ -21,6 +21,22 @@
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   216
 #include "libxml.h"
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   217
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   218
 #include <string.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   219
+#ifdef HAVE_STDLIB_H
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   220
+#include <stdlib.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   221
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   222
+#ifdef HAVE_TIME_H
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   223
+#include <time.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   224
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   225
+
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   226
+/*
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   227
+ * Following http://www.ocert.org/advisories/ocert-2011-003.html
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   228
+ * it seems that having hash randomization might be a good idea
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   229
+ * when using XML with untrusted data
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   230
+ */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   231
+#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(HAVE_TIME)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   232
+#define HASH_RANDOMIZATION
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   233
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   234
+
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   235
 #include <libxml/parser.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   236
 #include <libxml/hash.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   237
 #include <libxml/xmlmemory.h>
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   238
@@ -31,6 +47,10 @@
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   239
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   240
 /* #define DEBUG_GROW */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   241
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   242
+#ifdef HASH_RANDOMIZATION
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   243
+static int hash_initialized = 0;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   244
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   245
+
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   246
 /*
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   247
  * A single entry in the hash table
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   248
  */
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   249
@@ -53,6 +73,9 @@ struct _xmlHashTable {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   250
     int size;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   251
     int nbElems;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   252
     xmlDictPtr dict;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   253
+#ifdef HASH_RANDOMIZATION
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   254
+    int random_seed;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   255
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   256
 };
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   257
 
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   258
 /*
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   259
@@ -65,6 +88,9 @@ xmlHashComputeKey(xmlHashTablePtr table, const xmlChar *name,
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   260
     unsigned long value = 0L;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   261
     char ch;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   262
     
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   263
+#ifdef HASH_RANDOMIZATION
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   264
+    value = table->random_seed;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   265
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   266
     if (name != NULL) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   267
 	value += 30 * (*name);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   268
 	while ((ch = *name++) != 0) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   269
@@ -92,6 +118,9 @@ xmlHashComputeQKey(xmlHashTablePtr table,
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   270
     unsigned long value = 0L;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   271
     char ch;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   272
     
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   273
+#ifdef HASH_RANDOMIZATION
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   274
+    value = table->random_seed;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   275
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   276
     if (prefix != NULL)
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   277
 	value += 30 * (*prefix);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   278
     else
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   279
@@ -156,6 +185,13 @@ xmlHashCreate(int size) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   280
         table->table = xmlMalloc(size * sizeof(xmlHashEntry));
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   281
         if (table->table) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   282
   	    memset(table->table, 0, size * sizeof(xmlHashEntry));
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   283
+#ifdef HASH_RANDOMIZATION
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   284
+            if (!hash_initialized) {
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   285
+                srand(time(NULL));
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   286
+                hash_initialized = 1;
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   287
+            }
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   288
+            table->random_seed = rand();
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   289
+#endif
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   290
   	    return(table);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   291
         }
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   292
         xmlFree(table);
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   293
--
bb69a554cd60 7008726 Problem with library/libxml
Kevin Crowe <Kevin.Crowe@oracle.com>
parents:
diff changeset
   294
cgit v0.9.0.2