From 9cb605f4fb675db1bec08aa57fcc9840770b3dcf Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Thu, 2 Oct 2025 11:15:53 +0500 Subject: [PATCH] Replaced rand() with random() --- lib/PgSQL_Protocol.cpp | 6 ++---- src/main.cpp | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/PgSQL_Protocol.cpp b/lib/PgSQL_Protocol.cpp index 51189603f..0a2a15cbd 100644 --- a/lib/PgSQL_Protocol.cpp +++ b/lib/PgSQL_Protocol.cpp @@ -1319,10 +1319,8 @@ void PgSQL_Protocol::welcome_client() { uint32_t backend_pid = (*myds)->sess->thread_session_id; uint32_t cancel_key = -1; if (RAND_bytes((unsigned char*)&cancel_key, sizeof(cancel_key)) != 1) { - // Fallback method: using a basic pseudo-random generator - srand((unsigned int)time(NULL)); - auto rand_val = rand() % 256; - memcpy(&cancel_key, &rand_val, sizeof(cancel_key)); + // Fallback: use libc PRNG + cancel_key = (uint32_t)random(); } (*myds)->sess->cancel_secret_key = cancel_key; diff --git a/src/main.cpp b/src/main.cpp index 71d25c40e..52ee9ef4a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1460,6 +1460,7 @@ void ProxySQL_Main_init_phase2___not_started(const bootstrap_info_t& boostrap_in void ProxySQL_Main_init_phase3___start_all() { + srandom((unsigned int)(time(NULL) ^ getpid())); { cpu_timer t; GloMyLogger->events_set_datadir(GloVars.datadir);