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)
downloadeina-2fdedc3c18f0d77ee652e3ae91d7865390836a57.tar.gz
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 @@
2013-01-05 Joel Klinghed
* configure dirfd check fix
-
+
+2013-02-06 Cedric Bail
+
+ * 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 @@
-Eina 1.7.5
+Eina 1.7.6
+
+Changes since Eina 1.7.5:
+-------------------------
+
+ * Prevent denial of service on Eina_Hash function.
Changes since Eina 1.7.4:
-------------------------
@@ -6,6 +11,7 @@ Changes since Eina 1.7.4:
No changes, just updating to keep in sync with last release.
Changes since Eina 1.7.3:
+-------------------------
* Fix EINA_INLIST_FOREACH_SAFE macro
* Add XML output to doc
@@ -32,6 +38,8 @@ Fixes:
* Fix eina_stringshare_add_length() to return NULL when wrong.
* Add EINA_SAFETY checks are wrong.
+Eina 1.7.0
+
Changes since Eina 1.2.0:
-------------------------
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 @@
#ifndef EINA_INLINE_HASH_X_
#define EINA_INLINE_HASH_X_
+EAPI extern unsigned int eina_seed;
+
/*
djb2 hash algorithm was first reported by dan bernstein, and was the old
default hash function for evas.
@@ -26,7 +28,7 @@
static inline int
eina_hash_djb2(const char *key, int len)
{
- unsigned int hash_num = 5381;
+ unsigned int hash_num = 5381 ^ eina_seed;
const unsigned char *ptr;
if (!key) return 0;
@@ -39,7 +41,7 @@ eina_hash_djb2(const char *key, int len)
static inline int
eina_hash_djb2_len(const char *key, int *plen)
{
- unsigned int hash_num = 5381;
+ unsigned int hash_num = 5381 ^ eina_seed;
int len = 0;
const unsigned char *ptr;
@@ -64,7 +66,7 @@ eina_hash_int32(const unsigned int *pkey, int len)
key ^= key >> 12;
key += key << 2;
key ^= key >> 4;
- key *= 2057;
+ key *= 2057 ^ eina_seed;
key ^= key >> 16;
return key;
}
@@ -78,7 +80,7 @@ eina_hash_int64(const unsigned long int *pkey, int len)
key = ~key + (key << 18);
key ^= key >> 31;
- key *= 21;
+ key *= 21 ^ eina_seed;
key ^= key >> 11;
key += key << 6;
key ^= key >> 22;
@@ -107,8 +109,8 @@ eina_hash_murmur3(const char *key, int len)
const unsigned char * data = (const unsigned char*)key;
const int nblocks = len / 4;
unsigned int h1 = 0, k1;
- unsigned int c1 = 0xcc9e2d51;
- unsigned int c2 = 0x1b873593;
+ unsigned int c1 = 0xcc9e2d51 ^ eina_seed;
+ unsigned int c2 = 0x1b873593 ^ eina_seed;
const unsigned int * blocks = (const unsigned int *)(data + nblocks*4);
int i;
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)
EAPI int
eina_hash_superfast(const char *key, int len)
{
- int hash = len, tmp;
+ int hash = len ^ eina_seed, tmp;
int rem;
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;
EAPI Eina_Bool _eina_threads_activated = EINA_FALSE;
EAPI Eina_Error EINA_ERROR_NOT_MAIN_LOOP = 0;
+EAPI unsigned int eina_seed = 0;
static const char EINA_ERROR_NOT_MAIN_LOOP_STR[] = "Main loop thread check failed.";
@@ -245,6 +246,10 @@ eina_init(void)
if (EINA_LIKELY(_eina_main_count > 0))
return ++_eina_main_count;
+ srand(time(NULL));
+ while (eina_seed == 0)
+ eina_seed = rand();
+
#ifdef MT
if ((getenv("EINA_MTRACE")) && (getenv("MALLOC_TRACE")))
{