[4/4] libmsc: Use RAND_bytes to generate a token
diff mbox

Message ID bfc91187558c5911c98de6ab58603c28c99c7ed5.1444298449.git.daniel@totalueberwachung.de
State Accepted
Headers show

Commit Message

Daniel Willmann Oct. 8, 2015, 2:10 p.m. UTC
From: Daniel Willmann <dwillmann@sysmocom.de>

---
 openbsc/src/libmsc/db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Patch
diff mbox

diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c
index faae982..863a092 100644
--- a/openbsc/src/libmsc/db.c
+++ b/openbsc/src/libmsc/db.c
@@ -1275,7 +1275,10 @@  int db_subscriber_alloc_token(struct gsm_subscriber *subscriber, uint32_t *token
 	uint32_t try;
 
 	for (;;) {
-		try = rand();
+		if (RAND_bytes(&try, sizeof(try)) != 1) {
+			LOGP(DDB, LOGL_ERROR, "RAND_bytes failed\n");
+			return 1;
+		}
 		if (!try) /* 0 is an invalid token */
 			continue;
 		result = dbi_conn_queryf(conn,