summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2013-02-06 06:56:42 +0000
committerCedric BAIL <cedric.bail@free.fr>2013-02-06 06:56:42 +0000
commit2fdedc3c18f0d77ee652e3ae91d7865390836a57 (patch)
tree455faa20cffcd14a133b90e6f2643694c89f5ca7
parent0d725bafadabdc070f10724270db8cdbecaac939 (diff)
eina: backport r83578.
SVN revision: 83652
-rw-r--r--ChangeLog5
-rw-r--r--NEWS10
-rw-r--r--src/include/eina_inline_hash.x14
-rw-r--r--src/lib/eina_hash.c2
-rw-r--r--src/lib/eina_main.c5
5 files changed, 27 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index e093e36..6ade1a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -397,4 +397,7 @@
3972013-01-05 Joel Klinghed 3972013-01-05 Joel Klinghed
398 398
399 * configure dirfd check fix 399 * configure dirfd check fix
400 400
4012013-02-06 Cedric Bail
402
403 * eina: counter measure denial of service on eina_hash function.
diff --git a/NEWS b/NEWS
index 4227e6a..f6fa5df 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,9 @@
1Eina 1.7.5 1Eina 1.7.6
2
3Changes since Eina 1.7.5:
4-------------------------
5
6 * Prevent denial of service on Eina_Hash function.
2 7
3Changes since Eina 1.7.4: 8Changes since Eina 1.7.4:
4------------------------- 9-------------------------
@@ -6,6 +11,7 @@ Changes since Eina 1.7.4:
6No changes, just updating to keep in sync with last release. 11No changes, just updating to keep in sync with last release.
7 12
8Changes since Eina 1.7.3: 13Changes since Eina 1.7.3:
14-------------------------
9 15
10 * Fix EINA_INLIST_FOREACH_SAFE macro 16 * Fix EINA_INLIST_FOREACH_SAFE macro
11 * Add XML output to doc 17 * Add XML output to doc
@@ -32,6 +38,8 @@ Fixes:
32 * Fix eina_stringshare_add_length() to return NULL when wrong. 38 * Fix eina_stringshare_add_length() to return NULL when wrong.
33 * Add EINA_SAFETY checks are wrong. 39 * Add EINA_SAFETY checks are wrong.
34 40
41Eina 1.7.0
42
35Changes since Eina 1.2.0: 43Changes since Eina 1.2.0:
36------------------------- 44-------------------------
37 45
diff --git a/src/include/eina_inline_hash.x b/src/include/eina_inline_hash.x
index be20e8f..b2fc3f3 100644
--- a/src/include/eina_inline_hash.x
+++ b/src/include/eina_inline_hash.x
@@ -19,6 +19,8 @@
19#ifndef EINA_INLINE_HASH_X_ 19#ifndef EINA_INLINE_HASH_X_
20#define EINA_INLINE_HASH_X_ 20#define EINA_INLINE_HASH_X_
21 21
22EAPI extern unsigned int eina_seed;
23
22/* 24/*
23 djb2 hash algorithm was first reported by dan bernstein, and was the old 25 djb2 hash algorithm was first reported by dan bernstein, and was the old
24 default hash function for evas. 26 default hash function for evas.
@@ -26,7 +28,7 @@
26static inline int 28static inline int
27eina_hash_djb2(const char *key, int len) 29eina_hash_djb2(const char *key, int len)
28{ 30{
29 unsigned int hash_num = 5381; 31 unsigned int hash_num = 5381 ^ eina_seed;
30 const unsigned char *ptr; 32 const unsigned char *ptr;
31 33
32 if (!key) return 0; 34 if (!key) return 0;
@@ -39,7 +41,7 @@ eina_hash_djb2(const char *key, int len)
39static inline int 41static inline int
40eina_hash_djb2_len(const char *key, int *plen) 42eina_hash_djb2_len(const char *key, int *plen)
41{ 43{
42 unsigned int hash_num = 5381; 44 unsigned int hash_num = 5381 ^ eina_seed;
43 int len = 0; 45 int len = 0;
44 const unsigned char *ptr; 46 const unsigned char *ptr;
45 47
@@ -64,7 +66,7 @@ eina_hash_int32(const unsigned int *pkey, int len)
64 key ^= key >> 12; 66 key ^= key >> 12;
65 key += key << 2; 67 key += key << 2;
66 key ^= key >> 4; 68 key ^= key >> 4;
67 key *= 2057; 69 key *= 2057 ^ eina_seed;
68 key ^= key >> 16; 70 key ^= key >> 16;
69 return key; 71 return key;
70} 72}
@@ -78,7 +80,7 @@ eina_hash_int64(const unsigned long int *pkey, int len)
78 80
79 key = ~key + (key << 18); 81 key = ~key + (key << 18);
80 key ^= key >> 31; 82 key ^= key >> 31;
81 key *= 21; 83 key *= 21 ^ eina_seed;
82 key ^= key >> 11; 84 key ^= key >> 11;
83 key += key << 6; 85 key += key << 6;
84 key ^= key >> 22; 86 key ^= key >> 22;
@@ -107,8 +109,8 @@ eina_hash_murmur3(const char *key, int len)
107 const unsigned char * data = (const unsigned char*)key; 109 const unsigned char * data = (const unsigned char*)key;
108 const int nblocks = len / 4; 110 const int nblocks = len / 4;
109 unsigned int h1 = 0, k1; 111 unsigned int h1 = 0, k1;
110 unsigned int c1 = 0xcc9e2d51; 112 unsigned int c1 = 0xcc9e2d51 ^ eina_seed;
111 unsigned int c2 = 0x1b873593; 113 unsigned int c2 = 0x1b873593 ^ eina_seed;
112 const unsigned int * blocks = (const unsigned int *)(data + nblocks*4); 114 const unsigned int * blocks = (const unsigned int *)(data + nblocks*4);
113 int i; 115 int i;
114 const unsigned char *tail; 116 const unsigned char *tail;
diff --git a/src/lib/eina_hash.c b/src/lib/eina_hash.c
index 821d225..37b7751 100644
--- a/src/lib/eina_hash.c
+++ b/src/lib/eina_hash.c
@@ -1328,7 +1328,7 @@ eina_hash_iterator_tuple_new(const Eina_Hash *hash)
1328EAPI int 1328EAPI int
1329eina_hash_superfast(const char *key, int len) 1329eina_hash_superfast(const char *key, int len)
1330{ 1330{
1331 int hash = len, tmp; 1331 int hash = len ^ eina_seed, tmp;
1332 int rem; 1332 int rem;
1333 1333
1334 rem = len & 3; 1334 rem = len & 3;
diff --git a/src/lib/eina_main.c b/src/lib/eina_main.c
index e6236b9..e94a78a 100644
--- a/src/lib/eina_main.c
+++ b/src/lib/eina_main.c
@@ -101,6 +101,7 @@ static int _eina_log_dom = -1;
101 101
102EAPI Eina_Bool _eina_threads_activated = EINA_FALSE; 102EAPI Eina_Bool _eina_threads_activated = EINA_FALSE;
103EAPI Eina_Error EINA_ERROR_NOT_MAIN_LOOP = 0; 103EAPI Eina_Error EINA_ERROR_NOT_MAIN_LOOP = 0;
104EAPI unsigned int eina_seed = 0;
104 105
105static const char EINA_ERROR_NOT_MAIN_LOOP_STR[] = "Main loop thread check failed."; 106static const char EINA_ERROR_NOT_MAIN_LOOP_STR[] = "Main loop thread check failed.";
106 107
@@ -245,6 +246,10 @@ eina_init(void)
245 if (EINA_LIKELY(_eina_main_count > 0)) 246 if (EINA_LIKELY(_eina_main_count > 0))
246 return ++_eina_main_count; 247 return ++_eina_main_count;
247 248
249 srand(time(NULL));
250 while (eina_seed == 0)
251 eina_seed = rand();
252
248#ifdef MT 253#ifdef MT
249 if ((getenv("EINA_MTRACE")) && (getenv("MALLOC_TRACE"))) 254 if ((getenv("EINA_MTRACE")) && (getenv("MALLOC_TRACE")))
250 { 255 {