refactor: add safety check for protocol separator in URL reconstruction
Add validation to ensure "://" exists before extracting protocol. Prevents potential undefined behavior if malformed URLs are provided. Co-authored-by: connortechnology <925519+connortechnology@users.noreply.github.com>copilot/fix-rtsps-source-stream
parent
d54cb3f7c1
commit
371db6c6e3
|
|
@ -314,9 +314,14 @@ int FfmpegCamera::OpenFfmpeg() {
|
|||
|
||||
if (mUser.length() > 0) {
|
||||
// build the actual uri string with encoded parameters (from the user and pass fields)
|
||||
std::string fullProtocol = mPath.substr(0, mPath.find("://"));
|
||||
mPath = StringToLower(fullProtocol) + "://" + mUser + ":" + UriEncode(mPass) + "@" + mMaskedPath.substr(fullProtocol.length() + 3);
|
||||
Debug(1, "Rebuilt URI with encoded parameters: '%s'", mPath.c_str());
|
||||
std::size_t protoEnd = mPath.find("://");
|
||||
if (protoEnd != std::string::npos) {
|
||||
std::string fullProtocol = mPath.substr(0, protoEnd);
|
||||
mPath = StringToLower(fullProtocol) + "://" + mUser + ":" + UriEncode(mPass) + "@" + mMaskedPath.substr(fullProtocol.length() + 3);
|
||||
Debug(1, "Rebuilt URI with encoded parameters: '%s'", mPath.c_str());
|
||||
} else {
|
||||
Warning("Unable to add credentials to URL without protocol separator: %s", mMaskedPath.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
ret = avformat_open_input(&mFormatContext, mPath.c_str(), input_format, &opts);
|
||||
|
|
|
|||
|
|
@ -254,9 +254,14 @@ int LibvlcCamera::PrimeCapture() {
|
|||
std::string protocol = StringToUpper(mPath.substr(0, 4));
|
||||
if ( protocol == "RTSP" ) {
|
||||
// build the actual uri string with encoded parameters (from the user and pass fields)
|
||||
std::string fullProtocol = mPath.substr(0, mPath.find("://"));
|
||||
mPath = StringToLower(fullProtocol) + "://" + mUser + ":" + mPass + "@" + mMaskedPath.substr(fullProtocol.length() + 3);
|
||||
Debug(1, "Rebuilt URI with encoded parameters: '%s'", mPath.c_str());
|
||||
std::size_t protoEnd = mPath.find("://");
|
||||
if (protoEnd != std::string::npos) {
|
||||
std::string fullProtocol = mPath.substr(0, protoEnd);
|
||||
mPath = StringToLower(fullProtocol) + "://" + mUser + ":" + mPass + "@" + mMaskedPath.substr(fullProtocol.length() + 3);
|
||||
Debug(1, "Rebuilt URI with encoded parameters: '%s'", mPath.c_str());
|
||||
} else {
|
||||
Warning("Unable to add credentials to URL without protocol separator: %s", mMaskedPath.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue