shithub: riscv

Download patch

ref: a54fcac01609be9438f6fb05b4da4be01c303383
parent: 314faec39447f98c0dfd96a91dbd25fd757d106d
author: cinap_lenrek <[email protected]>
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;