Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SRT: Fix srt2rtmp crash when streamid is too long(#2770) #2786

Merged
merged 1 commit into from
Dec 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions trunk/src/srt/srt_to_rtmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <srs_app_config.hpp>
#include <srs_kernel_stream.hpp>
#include <list>
#include <sstream>
Copy link
Member

@chundonglinlin chundonglinlin Dec 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #include <sstream> has already been imported in the srs_app_config.hpp header file, so there is no need to repeat #include <sstream>.

TRANS_BY_GPT3

Copy link
Member

@chundonglinlin chundonglinlin Dec 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The crash issue has been verified and there are no other problems by using stringstream instead of a char array. Thanks to @akanchi for the pull request.

TRANS_BY_GPT3


std::shared_ptr<srt2rtmp> srt2rtmp::s_srt2rtmp_ptr;

Expand Down Expand Up @@ -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<std::string> ip_ports = _srs_config->get_listens();
int port = 0;
std::string ip;
Expand All @@ -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() {
Expand Down