ObjFW  Check-in [1b09ca22f3]

Overview
Comment:Make sure of_hash_seed is never initialized to 0

of_hash_seed == 0 is special, as it means to OFMapTable to behave
deterministically (which is required for the tests, for example) and not
do any random per-hashtable rotating on the hash. The random rotation
improves resistance against hash collision DoS attacks, so if the random
seed happens to be 0, it would disable that rotation unintentionally,
thus it's better to get a new random seed if it is 0.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 0.8
Files: files | file ages | folders
SHA3-256: 1b09ca22f34e69b97b964a057ca736ce6411958f97652d9eb8b91e65d8b65d76
User & Date: js on 2015-08-26 08:53:53
Other Links: branch diff | manifest | tags
Context
2015-08-26
09:07
OFZIPArchive: Throw invalid format on failed seek check-in: 022994c409 user: js tags: 0.8
08:53
Make sure of_hash_seed is never initialized to 0 check-in: 1b09ca22f3 user: js tags: 0.8
08:24
OFProcess: Send SIGTERM on close check-in: 397b4ee50b user: js tags: 0.8
Changes

Modified src/OFObject.m from [8a0142f57a] to [920a5b1adb].

226
227
228
229
230
231
232


233
234
235
236
237
238
239

240
241
242
243
244
245

246
247
248
249
250
251
252
	objc_setForwardHandler((IMP)&of_forward, (IMP)&of_forward_stret);
#endif

#ifdef HAVE_OBJC_ENUMERATIONMUTATION
	objc_setEnumerationMutationHandler(enumerationMutationHandler);
#endif



#if defined(HAVE_ARC4RANDOM)
	of_hash_seed = arc4random();
#elif defined(HAVE_RANDOM)
	struct timeval t;
	gettimeofday(&t, NULL);
	srandom((unsigned)(t.tv_sec ^ t.tv_usec));
	of_hash_seed = (uint32_t)((random() << 16) | (random() & 0xFFFF));

#else
	struct timeval t;
	gettimeofday(&t, NULL);
	srand((unsigned)(t.tv_sec ^ t.tv_usec));
	of_hash_seed = (uint32_t)((rand() << 16) | (rand() & 0xFFFF));
#endif

}

+ (void)unload
{
}

+ (void)initialize







>
>

|

|
|
|
|
>

|
|
|
|

>







226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
	objc_setForwardHandler((IMP)&of_forward, (IMP)&of_forward_stret);
#endif

#ifdef HAVE_OBJC_ENUMERATIONMUTATION
	objc_setEnumerationMutationHandler(enumerationMutationHandler);
#endif

	of_hash_seed = 0;
	while (of_hash_seed == 0) {
#if defined(HAVE_ARC4RANDOM)
		of_hash_seed = arc4random();
#elif defined(HAVE_RANDOM)
		struct timeval t;
		gettimeofday(&t, NULL);
		srandom((unsigned)(t.tv_sec ^ t.tv_usec));
		of_hash_seed = (uint32_t)((random() << 16) |
		    (random() & 0xFFFF));
#else
		struct timeval t;
		gettimeofday(&t, NULL);
		srand((unsigned)(t.tv_sec ^ t.tv_usec));
		of_hash_seed = (uint32_t)((rand() << 16) | (rand() & 0xFFFF));
#endif
	}
}

+ (void)unload
{
}

+ (void)initialize