From 9d79f85e556d6de7ec9ce89788691bb18802ad5c Mon Sep 17 00:00:00 2001 From: akanchi Date: Sat, 11 Dec 2021 20:50:00 +0800 Subject: [PATCH] SRT: Fix srt2rtmp crash when streamid is too long(#2770) --- trunk/src/srt/srt_to_rtmp.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/trunk/src/srt/srt_to_rtmp.cpp b/trunk/src/srt/srt_to_rtmp.cpp index c753d0d02a..a554a3e254 100644 --- a/trunk/src/srt/srt_to_rtmp.cpp +++ b/trunk/src/srt/srt_to_rtmp.cpp @@ -15,6 +15,7 @@ #include #include #include +#include std::shared_ptr srt2rtmp::s_srt2rtmp_ptr; @@ -258,8 +259,7 @@ rtmp_client::rtmp_client(std::string key_path):_key_path(key_path) _appname = ret_vec[0]; _streamname = ret_vec[1]; } - char url_sz[128]; - + std::vector ip_ports = _srs_config->get_listens(); int port = 0; std::string ip; @@ -271,22 +271,24 @@ rtmp_client::rtmp_client(std::string key_path):_key_path(key_path) } } port = (port == 0) ? 1935 : port; - if (_vhost == DEF_VHOST) { - sprintf(url_sz, "rtmp://127.0.0.1:%d/%s/%s", port, - _appname.c_str(), _streamname.c_str()); - } else { - sprintf(url_sz, "rtmp://127.0.0.1:%d/%s?vhost=%s/%s", port, - _appname.c_str(), _vhost.c_str(), _streamname.c_str()); + + std::stringstream ss; + ss << "rtmp://127.0.0.1"; + ss << ":" << port; + ss << "/" << _appname; + if (_vhost != DEF_VHOST) { + ss << "?vhost=" << _vhost; } - - _url = url_sz; + ss << "/" << _streamname; + + _url = ss.str(); _h264_sps_changed = false; _h264_pps_changed = false; _h264_sps_pps_sent = false; _last_live_ts = now_ms(); - srs_trace("rtmp client construct url:%s", url_sz); + srs_trace("rtmp client construct url:%s", _url.c_str()); } rtmp_client::~rtmp_client() {