diff --git a/README.md b/README.md index 561c0165b..99fd8ac6b 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 026ac8801..a0277f3c9 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -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"; } diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 6bc0b4cf2..c9c03e24f 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -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: diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index 1e6ae4371..831a0613a 100755 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -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; diff --git a/trunk/src/app/srs_app_st.hpp b/trunk/src/app/srs_app_st.hpp index 131ec697c..956e00b42 100644 --- a/trunk/src/app/srs_app_st.hpp +++ b/trunk/src/app/srs_app_st.hpp @@ -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. diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index d82dfdf6a..2dc149ddc 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -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"; } diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index 26da0106d..be7cbced6 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -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); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index b4b9edbd5..0eb763b92 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -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 diff --git a/trunk/src/kernel/srs_kernel_mp4.cpp b/trunk/src/kernel/srs_kernel_mp4.cpp index 1845a87b2..5cfc5ac9f 100644 --- a/trunk/src/kernel/srs_kernel_mp4.cpp +++ b/trunk/src/kernel/srs_kernel_mp4.cpp @@ -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()); diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp index 765a86546..04d386298 100644 --- a/trunk/src/kernel/srs_kernel_utility.hpp +++ b/trunk/src/kernel/srs_kernel_utility.hpp @@ -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 , 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". diff --git a/trunk/src/protocol/srs_protocol_json.cpp b/trunk/src/protocol/srs_protocol_json.cpp index 82f099114..c742bb158 100644 --- a/trunk/src/protocol/srs_protocol_json.cpp +++ b/trunk/src/protocol/srs_protocol_json.cpp @@ -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; diff --git a/trunk/src/protocol/srs_protocol_json.hpp b/trunk/src/protocol/srs_protocol_json.hpp index cac07a8d5..273b237dc 100644 --- a/trunk/src/protocol/srs_protocol_json.hpp +++ b/trunk/src/protocol/srs_protocol_json.hpp @@ -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 diff --git a/trunk/src/service/srs_service_utility.cpp b/trunk/src/service/srs_service_utility.cpp index 4d19133f4..108240bdb 100644 --- a/trunk/src/service/srs_service_utility.cpp +++ b/trunk/src/service/srs_service_utility.cpp @@ -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; diff --git a/trunk/src/service/srs_service_utility.hpp b/trunk/src/service/srs_service_utility.hpp index c41a86215..ce1acc3ed 100644 --- a/trunk/src/service/srs_service_utility.hpp +++ b/trunk/src/service/srs_service_utility.hpp @@ -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& srs_get_local_ips(); diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index 9868749d5..181bc58b1 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -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;