ref: 062ea51567ed0799de34c07c10263abcba0831b6
parent: 16edac9be06c8c4300b888b131708d8448150a9b
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Apr 21 09:10:39 EDT 2024
devsdp: fix randomization of dial and acceptid We where allocating the dialid and acceptid using: rand()<<16 + rand() this gives a biased values as rand() retuns a 15-bit number. Instead, use two calls to nrand() to get the full 32-bit unsigned range.
--- a/sys/src/9/port/devsdp.c
+++ b/sys/src/9/port/devsdp.c
@@ -964,13 +964,13 @@
panic("setstate: bad state: %d", state);
case CDial:
assert(c->state == CInit);
- c->dialid = (rand()<<16) + rand();
+ c->dialid = (nrand(1<<16)<<16)|nrand(1<<16);
convretryinit(c);
convoconnect(c, ConOpenRequest, c->dialid, 0);
break;
case CAccept:
assert(c->state == CInit);
- c->acceptid = (rand()<<16) + rand();
+ c->acceptid = (nrand(1<<16)<<16)|nrand(1<<16);
convretryinit(c);
convoconnect(c, ConOpenAck, c->dialid, c->acceptid);
break;
--
⑨