1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #2424, use srandom/random to generate. 3.0.164

This commit is contained in:
winlin 2021-07-04 13:10:42 +08:00
parent e7435a6237
commit d72d05294d
10 changed files with 25 additions and 16 deletions

1
trunk/.gitignore vendored
View file

@ -13,6 +13,7 @@
/ide/srs_xcode/srs_xcode.xcodeproj/xcuserdata/
/research/aac/
/research/api-server/static-dir/mse
/research/api-server/static-dir/crossdomain.xml
/research/bat/
/research/big/
/research/bitch/

View file

@ -1,3 +0,0 @@
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>

View file

@ -484,7 +484,7 @@ void SrsIngester::show_ingest_log_message()
}
// random choose one ingester to report.
int index = rand() % (int)ingesters.size();
int index = srs_random() % (int)ingesters.size();
SrsIngesterFFMPEG* ingester = ingesters.at(index);
// reportable

View file

@ -54,7 +54,7 @@ srs_error_t SrsLatestVersion::start()
return srs_success;
}
char buf[10];
char buf[16];
srs_random_generate(buf, sizeof(buf));
for (int i = 0; i < (int)sizeof(buf); i++) {
buf[i] = 'a' + uint8_t(buf[i])%25;

View file

@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION3_HPP
#define SRS_CORE_VERSION3_HPP
#define SRS_VERSION3_REVISION 163
#define SRS_VERSION3_REVISION 164
#endif

View file

@ -119,7 +119,7 @@ srs_utime_t srs_get_system_startup_time()
if (_srs_system_time_startup_time <= 0) {
srs_update_system_time();
}
return _srs_system_time_startup_time;
}

View file

@ -150,18 +150,23 @@ void srs_parse_query_string(string q, map<string,string>& query)
void srs_random_generate(char* bytes, int size)
{
static bool _random_initialized = false;
if (!_random_initialized) {
srand(0);
_random_initialized = true;
}
for (int i = 0; i < size; i++) {
// the common value in [0x0f, 0xf0]
bytes[i] = 0x0f + (rand() % (256 - 0x0f - 0x0f));
bytes[i] = 0x0f + (srs_random() % (256 - 0x0f - 0x0f));
}
}
long srs_random()
{
static bool _random_initialized = false;
if (!_random_initialized) {
_random_initialized = true;
srandom((unsigned int)srs_get_system_startup_time());
}
return random();
}
string srs_generate_tc_url(string host, string vhost, string app, int port)
{
string tcUrl = "rtmp://";

View file

@ -69,6 +69,8 @@ extern void srs_parse_query_string(std::string q, std::map<std::string, std::str
* generate ramdom data for handshake.
*/
extern void srs_random_generate(char* bytes, int size);
// Generate random value, use srandom(now_us) to init seed if not initialized.
extern long srs_random();
/**
* generate the tcUrl without param.

View file

@ -357,7 +357,7 @@ namespace srs_internal
key_block::key_block()
{
offset = (int32_t)rand();
offset = (int32_t)srs_random();
random0 = NULL;
random1 = NULL;
@ -439,7 +439,7 @@ namespace srs_internal
digest_block::digest_block()
{
offset = (int32_t)rand();
offset = (int32_t)srs_random();
random0 = NULL;
random1 = NULL;