Overview
Comment: | Randomize hashes.
This prevents DoSing hashtables by creating conflicts deliberately. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f60e4012b7a099f0c724219d82e77a29 |
User & Date: | js on 2012-12-04 09:19:58 |
Other Links: | manifest | tags |
Context
2012-12-04
| ||
09:59 | Add a per-hashtable seed. check-in: 590fa6ed79 user: js tags: trunk | |
09:19 | Randomize hashes. check-in: f60e4012b7 user: js tags: trunk | |
2012-12-03
| ||
01:17 | OFXMLParser: Add configurable depth limit. check-in: ed4e64fd32 user: js tags: trunk | |
Changes
Modified configure.ac from [f33cdcae46] to [a9440db0fe].
︙ | ︙ | |||
393 394 395 396 397 398 399 400 401 402 403 404 405 406 | ac_cv_snprintf_useful_ret="no" ]) ]) AC_MSG_RESULT($ac_cv_snprintf_useful_ret) ]) test x"$have_asprintf" != x"yes" -a x"$ac_cv_snprintf_useful_ret" != x"yes" && \ AC_MSG_ERROR(No asprintf and no snprintf returning required space!) AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl") AC_ARG_ENABLE(threads, AS_HELP_STRING([--disable-threads], [disable thread support])) AS_IF([test x"$enable_threads" != x"no"], [ case "$host_os" in | > > > > > > > > | 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | ac_cv_snprintf_useful_ret="no" ]) ]) AC_MSG_RESULT($ac_cv_snprintf_useful_ret) ]) test x"$have_asprintf" != x"yes" -a x"$ac_cv_snprintf_useful_ret" != x"yes" && \ AC_MSG_ERROR(No asprintf and no snprintf returning required space!) AC_CHECK_FUNC(arc4random, [ AC_DEFINE(OF_HAVE_ARC4RANDOM, 1, [Whether we have arc4random()]) ], [ AC_CHECK_FUNC(random, [ AC_DEFINE(OF_HAVE_RANDOM, 1, [Whether we have random()]) ]) ]) AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl") AC_ARG_ENABLE(threads, AS_HELP_STRING([--disable-threads], [disable thread support])) AS_IF([test x"$enable_threads" != x"no"], [ case "$host_os" in |
︙ | ︙ |
Modified src/OFObject.h from [710d8a991e] to [c663f1ca8f].
︙ | ︙ | |||
871 872 873 874 875 876 877 878 879 | @end #import "OFObject+Serialization.h" #ifdef __cplusplus extern "C" { #endif extern size_t of_pagesize; extern size_t of_num_cpus; | > > < | | 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 | @end #import "OFObject+Serialization.h" #ifdef __cplusplus extern "C" { #endif extern id of_alloc_object(Class class_, size_t extraSize, size_t extraAlignment, void **extra); extern size_t of_pagesize; extern size_t of_num_cpus; extern uint32_t of_hash_seed; #ifdef __cplusplus } #endif |
Modified src/OFObject.m from [2f06cacc09] to [df05949c71].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <stdlib.h> #include <string.h> #include <unistd.h> #include <assert.h> #ifdef __QNX__ # include <sys/syspage.h> #endif #import "OFObject.h" #import "OFTimer.h" #import "OFThread.h" | > > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <stdlib.h> #include <string.h> #include <unistd.h> #include <assert.h> #include <sys/time.h> #ifdef __QNX__ # include <sys/syspage.h> #endif #import "OFObject.h" #import "OFTimer.h" #import "OFThread.h" |
︙ | ︙ | |||
95 96 97 98 99 100 101 102 103 104 105 106 107 108 | static struct { Class isa; } alloc_failed_exception; size_t of_pagesize; size_t of_num_cpus; #if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__) static void uncaught_exception_handler(id exception) { fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n", [[exception description] UTF8String]); | > | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | static struct { Class isa; } alloc_failed_exception; size_t of_pagesize; size_t of_num_cpus; uint32_t of_hash_seed; #if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__) static void uncaught_exception_handler(id exception) { fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n", [[exception description] UTF8String]); |
︙ | ︙ | |||
271 272 273 274 275 276 277 278 279 280 281 282 283 284 | # endif of_pagesize = 4096; # ifdef _SC_NPROCESSORS_CONF if ((of_num_cpus = sysconf(_SC_NPROCESSORS_CONF)) < 1) # endif of_num_cpus = 1; #endif } + (void)initialize { } + alloc | > > > > > > > > > > > > > > | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | # endif of_pagesize = 4096; # ifdef _SC_NPROCESSORS_CONF if ((of_num_cpus = sysconf(_SC_NPROCESSORS_CONF)) < 1) # endif of_num_cpus = 1; #endif #if defined(OF_HAVE_ARC4RANDOM) of_hash_seed = arc4random(); #elif defined(OF_HAVE_RANDOM) struct timeval t; gettimeofday(&t, NULL); srandom(t.tv_usec); of_hash_seed = random(); #else struct timeval t; gettimeofday(&t, NULL); srand(t.tv_usec); of_hash_seed = rand(); #endif } + (void)initialize { } + alloc |
︙ | ︙ |
Modified src/macros.h from [f956fa931a] to [419a2f32d2].
︙ | ︙ | |||
322 323 324 325 326 327 328 | # define OF_IOS #endif #define OF_ROL(value, bits) \ (((value) << ((bits) % (sizeof(value) * 8))) | \ (value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) | | | 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | # define OF_IOS #endif #define OF_ROL(value, bits) \ (((value) << ((bits) % (sizeof(value) * 8))) | \ (value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) #define OF_HASH_INIT(hash) hash = of_hash_seed #define OF_HASH_ADD(hash, byte) \ { \ hash += (uint8_t)byte; \ hash += (hash << 10); \ hash ^= (hash >> 6); \ } #define OF_HASH_FINALIZE(hash) \ |
︙ | ︙ |
Modified tests/TestsAppDelegate.m from [e7f245ce3b] to [cbb72ed2a0].
︙ | ︙ | |||
25 26 27 28 29 30 31 | #ifdef _PSP # include <pspmoduleinfo.h> # include <pspkernel.h> # include <pspdebug.h> PSP_MODULE_INFO("ObjFW Tests", 0, 0, 0); #endif | > > > > > | > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #ifdef _PSP # include <pspmoduleinfo.h> # include <pspkernel.h> # include <pspdebug.h> PSP_MODULE_INFO("ObjFW Tests", 0, 0, 0); #endif int main(int argc, char *argv[]) { /* We need deterministic hashes for tests */ of_hash_seed = 0; return of_application_main(&argc, &argv, [TestsAppDelegate class]); } @implementation TestsAppDelegate - (void)outputString: (OFString*)str withColor: (int)color { #if defined(_PSP) char i, space = ' '; |
︙ | ︙ |