From: Otto Moerbeek Date: Mon, 19 Jun 2023 09:33:02 +0000 (+0200) Subject: Convert a couple of calls from dns_random() to dns_random_uint32() X-Git-Tag: rec-5.0.0-alpha1~170^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12913%2Fhead;p=thirdparty%2Fpdns.git Convert a couple of calls from dns_random() to dns_random_uint32() --- diff --git a/pdns/lua-base4.cc b/pdns/lua-base4.cc index a0fb5892d3..2eae10d949 100644 --- a/pdns/lua-base4.cc +++ b/pdns/lua-base4.cc @@ -239,7 +239,9 @@ void BaseLua4::prepareContext() { SLOG(g_log << (Logger::Urgency)loglevel.get_value_or(Logger::Warning) << msg<withName("lua")->info(static_cast(loglevel.get_value_or(Logr::Warning)), msg)); }); - d_lw->writeFunction("pdnsrandom", [](boost::optional maximum) { return dns_random(maximum.get_value_or(0xffffffff)); }); + d_lw->writeFunction("pdnsrandom", [](boost::optional maximum) { + return maximum ? dns_random(*maximum) : dns_random_uint32(); + }); // certain constants diff --git a/pdns/opensslsigners.cc b/pdns/opensslsigners.cc index a8ca7c0712..9b593aa2da 100644 --- a/pdns/opensslsigners.cc +++ b/pdns/opensslsigners.cc @@ -180,7 +180,7 @@ void openssl_seed() unsigned int r; for (int i = 0; i < 1024; i += 4) { - r = dns_random(0xffffffff); + r = dns_random_uint32(); entropy.append((const char*)&r, 4); } diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index 6e0466a970..525b4636f4 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -1852,7 +1852,7 @@ static void testSpeed(const DNSName& zone, const string& /* remote */, int cores DTime dt; dt.set(); for(unsigned int n=0; n < 100000; ++n) { - rnd = dns_random(UINT32_MAX); + rnd = dns_random_uint32(); snprintf(tmp, sizeof(tmp), "%d.%d.%d.%d", octets[0], octets[1], octets[2], octets[3]); rr.content=tmp; diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 1b54fa7fa9..5199df79c0 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -1962,7 +1962,7 @@ static int serviceMain(Logr::log_t log) showProductVersion(); - g_disthashseed = dns_random(0xffffffff); + g_disthashseed = dns_random_uint32(); int ret = initNet(log); if (ret != 0) { diff --git a/pdns/tsigutils.cc b/pdns/tsigutils.cc index 40f49a9119..e81386bd8f 100644 --- a/pdns/tsigutils.cc +++ b/pdns/tsigutils.cc @@ -51,7 +51,7 @@ std::string makeTSIGKey(const DNSName& algorithm) { // Fill out the key for (size_t i = 0; i < klen; i += sizeof(uint32_t)) { - uint32_t t = dns_random(std::numeric_limits::max()); + uint32_t t = dns_random_uint32(); memcpy(&tmpkey.at(i), &t, sizeof(uint32_t)); }