mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 19:31:53 +00:00
Always use string instance to avoid crash risk. 3.0.95
This commit is contained in:
parent
b794c9e4ec
commit
10464a5fbe
15 changed files with 119 additions and 14 deletions
|
@ -146,6 +146,7 @@ For previous versions, please read:
|
|||
|
||||
## V3 changes
|
||||
|
||||
* v3.0, 2020-01-05, Always use string instance to avoid crash risk. 3.0.95
|
||||
* v3.0, 2020-01-05, For [#460][bug #460], fix ipv6 hostport parsing bug. 3.0.94
|
||||
* v3.0, 2020-01-05, For [#460][bug #460], fix ipv6 intranet address filter bug. 3.0.93
|
||||
* v3.0, 2020-01-05, For [#1543][bug #1543], use getpeername to retrieve client ip. 3.0.92
|
||||
|
|
|
@ -296,7 +296,7 @@ bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req)
|
|||
return false;
|
||||
}
|
||||
|
||||
string srs_config_bool2switch(const string& sbool)
|
||||
string srs_config_bool2switch(string sbool)
|
||||
{
|
||||
return sbool == "true"? "on":"off";
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ extern bool srs_stream_caster_is_flv(std::string caster);
|
|||
extern bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req);
|
||||
|
||||
// Convert bool in str to on/off
|
||||
extern std::string srs_config_bool2switch(const std::string& sbool);
|
||||
extern std::string srs_config_bool2switch(std::string sbool);
|
||||
|
||||
// Parse loaded vhost directives to compatible mode.
|
||||
// For exmaple, SRS1/2 use the follow refer style:
|
||||
|
|
|
@ -81,7 +81,7 @@ int SrsDummyCoroutine::cid()
|
|||
|
||||
_ST_THREAD_CREATE_PFN _pfn_st_thread_create = (_ST_THREAD_CREATE_PFN)st_thread_create;
|
||||
|
||||
SrsSTCoroutine::SrsSTCoroutine(const string& n, ISrsCoroutineHandler* h, int cid)
|
||||
SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h, int cid)
|
||||
{
|
||||
name = n;
|
||||
handler = h;
|
||||
|
|
|
@ -132,7 +132,7 @@ private:
|
|||
public:
|
||||
// Create a thread with name n and handler h.
|
||||
// @remark User can specify a cid for thread to use, or we will allocate a new one.
|
||||
SrsSTCoroutine(const std::string& n, ISrsCoroutineHandler* h, int cid = 0);
|
||||
SrsSTCoroutine(std::string n, ISrsCoroutineHandler* h, int cid = 0);
|
||||
virtual ~SrsSTCoroutine();
|
||||
public:
|
||||
// Start the thread.
|
||||
|
|
|
@ -1157,7 +1157,7 @@ string srs_get_peer_ip(int fd)
|
|||
return std::string(saddr);
|
||||
}
|
||||
|
||||
bool srs_is_boolean(const string& str)
|
||||
bool srs_is_boolean(string str)
|
||||
{
|
||||
return str == "true" || str == "false";
|
||||
}
|
||||
|
|
|
@ -644,7 +644,7 @@ extern std::string srs_get_peer_ip(int fd);
|
|||
// is_bool("true") == true
|
||||
// is_bool("false") == true
|
||||
// otherwise, false.
|
||||
extern bool srs_is_boolean(const std::string& str);
|
||||
extern bool srs_is_boolean(std::string str);
|
||||
|
||||
// Dump summaries for /api/v1/summaries.
|
||||
extern void srs_api_dump_summaries(SrsJsonObject* obj);
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
// The version config.
|
||||
#define VERSION_MAJOR 3
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 94
|
||||
#define VERSION_REVISION 95
|
||||
|
||||
// The macros generated by configure script.
|
||||
#include <srs_auto_headers.hpp>
|
||||
|
|
|
@ -110,12 +110,12 @@ void srs_mp4_delimiter_newline(stringstream& ss, SrsMp4DumpContext dc)
|
|||
srs_mp4_padding(ss, dc);
|
||||
}
|
||||
|
||||
int srs_mp4_string_length(const string& v)
|
||||
int srs_mp4_string_length(string v)
|
||||
{
|
||||
return (int)v.length()+1;
|
||||
}
|
||||
|
||||
void srs_mp4_string_write(SrsBuffer* buf, const string& v)
|
||||
void srs_mp4_string_write(SrsBuffer* buf, string v)
|
||||
{
|
||||
if (!v.empty()) {
|
||||
buf->write_bytes((char*)v.data(), (int)v.length());
|
||||
|
|
|
@ -56,7 +56,7 @@ extern std::string srs_dns_resolve(std::string host, int& family);
|
|||
|
||||
// Split the host:port to host and port.
|
||||
// @remark the hostport format in <host[:port]>, where port is optional.
|
||||
extern void srs_parse_hostport(const std::string& hostport, std::string& host, int& port);
|
||||
extern void srs_parse_hostport(std::string hostport, std::string& host, int& port);
|
||||
|
||||
// Parse the endpoint to ip and port.
|
||||
// @remark The hostport format in <[ip:]port>, where ip is default to "0.0.0.0".
|
||||
|
|
|
@ -1731,7 +1731,7 @@ SrsJsonAny* srs_json_parse_tree(json_value* node)
|
|||
}
|
||||
}
|
||||
|
||||
SrsJsonAny* SrsJsonAny::loads(const string& str)
|
||||
SrsJsonAny* SrsJsonAny::loads(string str)
|
||||
{
|
||||
if (str.empty()) {
|
||||
return NULL;
|
||||
|
|
|
@ -107,7 +107,7 @@ public:
|
|||
public:
|
||||
// Read json tree from string.
|
||||
// @return json object. NULL if error.
|
||||
static SrsJsonAny* loads(const std::string& str);
|
||||
static SrsJsonAny* loads(std::string str);
|
||||
};
|
||||
|
||||
class SrsJsonObject : public SrsJsonAny
|
||||
|
|
|
@ -51,7 +51,7 @@ bool srs_string_is_rtmp(string url)
|
|||
return srs_string_starts_with(url, "rtmp://");
|
||||
}
|
||||
|
||||
bool srs_is_digit_number(const string& str)
|
||||
bool srs_is_digit_number(string str)
|
||||
{
|
||||
if (str.empty()) {
|
||||
return false;
|
||||
|
|
|
@ -48,7 +48,7 @@ extern bool srs_string_is_rtmp(std::string url);
|
|||
// is_digit("10e3") === false
|
||||
// is_digit("!1234567890") === false
|
||||
// is_digit("") === false
|
||||
extern bool srs_is_digit_number(const std::string& str);
|
||||
extern bool srs_is_digit_number(std::string str);
|
||||
|
||||
// Get local ip, fill to @param ips
|
||||
extern std::vector<std::string>& srs_get_local_ips();
|
||||
|
|
|
@ -4254,6 +4254,110 @@ VOID TEST(KernelUtilityTest, CoverTimeUtilityAll)
|
|||
_srs_system_time_us_cache -= 300*1000 * 1000 + 1;
|
||||
EXPECT_TRUE(srs_update_system_time() > 0);
|
||||
|
||||
if (true) {
|
||||
string host = "127.0.0.1:1935";
|
||||
int port = 0;
|
||||
srs_parse_hostport(host, host, port);
|
||||
EXPECT_EQ(1935, port);
|
||||
EXPECT_STREQ("127.0.0.1", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 8080;
|
||||
srs_parse_hostport("::1", host, port);
|
||||
EXPECT_EQ(8080, port);
|
||||
EXPECT_STREQ("::1", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 8080;
|
||||
srs_parse_hostport("::", host, port);
|
||||
EXPECT_EQ(8080, port);
|
||||
EXPECT_STREQ("::", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 0;
|
||||
srs_parse_hostport("3ffe:dead:beef::1", host, port);
|
||||
EXPECT_EQ(0, port);
|
||||
EXPECT_STREQ("3ffe:dead:beef::1", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 10;
|
||||
srs_parse_hostport("2001:da8:6000:291:21f:d0ff:fed4:928c", host, port);
|
||||
EXPECT_EQ(10, port);
|
||||
EXPECT_STREQ("2001:da8:6000:291:21f:d0ff:fed4:928c", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 0;
|
||||
srs_parse_hostport("[2001:da8:6000:291:21f:d0ff:fed4:928c]:167", host, port);
|
||||
EXPECT_EQ(167, port);
|
||||
EXPECT_STREQ("2001:da8:6000:291:21f:d0ff:fed4:928c", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 0;
|
||||
srs_parse_hostport("[::A.B.C.D]:167", host, port);
|
||||
EXPECT_EQ(167, port);
|
||||
EXPECT_STREQ("::A.B.C.D", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 0;
|
||||
srs_parse_hostport("::A.B.C.D", host, port);
|
||||
EXPECT_EQ(0, port);
|
||||
EXPECT_STREQ("::A.B.C.D", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 0;
|
||||
srs_parse_hostport("[::FFFF:A.B.C.D]:167", host, port);
|
||||
EXPECT_EQ(167, port);
|
||||
EXPECT_STREQ("::FFFF:A.B.C.D", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 0;
|
||||
srs_parse_hostport("[ff00::]:167", host, port);
|
||||
EXPECT_EQ(167, port);
|
||||
EXPECT_STREQ("ff00::", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 0;
|
||||
srs_parse_hostport("[fe80::a00:27ff:fe84:be2%eth0]:167", host, port);
|
||||
EXPECT_EQ(167, port);
|
||||
EXPECT_STREQ("fe80::a00:27ff:fe84:be2%eth0", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 0;
|
||||
srs_parse_hostport("::FFFF:A.B.C.D", host, port);
|
||||
EXPECT_EQ(0, port);
|
||||
EXPECT_STREQ("::FFFF:A.B.C.D", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 8080;
|
||||
srs_parse_hostport("", host, port);
|
||||
EXPECT_EQ(8080, port);
|
||||
EXPECT_STREQ("", host.c_str());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
string host;
|
||||
int port = 8080;
|
||||
|
|
Loading…
Reference in a new issue