version 1.1.1.1, 2012/02/21 23:37:58
|
version 1.1.1.2, 2013/07/22 01:22:18
|
Line 3
|
Line 3
|
* |
* |
* Reference: Your favorite introductory book on algorithms |
* Reference: Your favorite introductory book on algorithms |
* |
* |
* Copyright (C) 2000 Bjorn Reese and Daniel Veillard. | * Copyright (C) 2000,2012 Bjorn Reese and Daniel Veillard. |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 21
|
Line 21
|
#include "libxml.h" |
#include "libxml.h" |
|
|
#include <string.h> |
#include <string.h> |
|
#ifdef HAVE_STDLIB_H |
|
#include <stdlib.h> |
|
#endif |
|
#ifdef HAVE_TIME_H |
|
#include <time.h> |
|
#endif |
|
|
|
/* |
|
* Following http://www.ocert.org/advisories/ocert-2011-003.html |
|
* it seems that having hash randomization might be a good idea |
|
* when using XML with untrusted data |
|
*/ |
|
#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(HAVE_TIME) |
|
#define HASH_RANDOMIZATION |
|
#endif |
|
|
#include <libxml/parser.h> |
#include <libxml/parser.h> |
#include <libxml/hash.h> |
#include <libxml/hash.h> |
#include <libxml/xmlmemory.h> |
#include <libxml/xmlmemory.h> |
Line 53 struct _xmlHashTable {
|
Line 69 struct _xmlHashTable {
|
int size; |
int size; |
int nbElems; |
int nbElems; |
xmlDictPtr dict; |
xmlDictPtr dict; |
|
#ifdef HASH_RANDOMIZATION |
|
int random_seed; |
|
#endif |
}; |
}; |
|
|
/* |
/* |
Line 65 xmlHashComputeKey(xmlHashTablePtr table, const xmlChar
|
Line 84 xmlHashComputeKey(xmlHashTablePtr table, const xmlChar
|
unsigned long value = 0L; |
unsigned long value = 0L; |
char ch; |
char ch; |
|
|
|
#ifdef HASH_RANDOMIZATION |
|
value = table->random_seed; |
|
#endif |
if (name != NULL) { |
if (name != NULL) { |
value += 30 * (*name); |
value += 30 * (*name); |
while ((ch = *name++) != 0) { |
while ((ch = *name++) != 0) { |
Line 92 xmlHashComputeQKey(xmlHashTablePtr table,
|
Line 114 xmlHashComputeQKey(xmlHashTablePtr table,
|
unsigned long value = 0L; |
unsigned long value = 0L; |
char ch; |
char ch; |
|
|
|
#ifdef HASH_RANDOMIZATION |
|
value = table->random_seed; |
|
#endif |
if (prefix != NULL) |
if (prefix != NULL) |
value += 30 * (*prefix); |
value += 30 * (*prefix); |
else |
else |
Line 156 xmlHashCreate(int size) {
|
Line 181 xmlHashCreate(int size) {
|
table->table = xmlMalloc(size * sizeof(xmlHashEntry)); |
table->table = xmlMalloc(size * sizeof(xmlHashEntry)); |
if (table->table) { |
if (table->table) { |
memset(table->table, 0, size * sizeof(xmlHashEntry)); |
memset(table->table, 0, size * sizeof(xmlHashEntry)); |
|
#ifdef HASH_RANDOMIZATION |
|
table->random_seed = __xmlRandom(); |
|
#endif |
return(table); |
return(table); |
} |
} |
xmlFree(table); |
xmlFree(table); |