diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 00c048dae..7eb48166b 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -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); diff --git a/src/zm_libvlc_camera.cpp b/src/zm_libvlc_camera.cpp index e910ba084..95117511a 100644 --- a/src/zm_libvlc_camera.cpp +++ b/src/zm_libvlc_camera.cpp @@ -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()); + } } }