ObjFW  Check-in [50e4ae0716]

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 | trunk
Files: files | file ages | folders
SHA3-256: 50e4ae071639ade14d2d2f2c675d48f55f9747c293c322acdaa9d55f7c891d0b
User & Date: js on 2015-08-26 08:50:09
Other Links: manifest | tags
Context
2015-08-26
09:05
OFZIPArchive: Throw invalid format on failed seek check-in: 89d2a684d3 user: js tags: trunk
08:50
Make sure of_hash_seed is never initialized to 0 check-in: 50e4ae0716 user: js tags: trunk
08:44
Rename support directory to misc check-in: 83df9c1cb0 user: js tags: trunk
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