Skip to content
Snippets Groups Projects
Commit b1120dc1 authored by Adrien Béraud's avatar Adrien Béraud Committed by gerrit2
Browse files

codec: catch potential stoi exception

All codec parameters are sent as strings and then some are converted
to numbers. The stoi conversion can throw an exception if a string
which is not actually an integer is passed and this should be caught.
The daemon should not crash from passing bad values via the dbus.

Change-Id: Ia42da689e08d601e0c94ad6ad14654ba9dfa8668
Tuleap: #215
parent 33a0aa38
No related branches found
No related tags found
No related merge requests found
...@@ -406,6 +406,7 @@ setCodecDetails(const std::string& accountID, ...@@ -406,6 +406,7 @@ setCodecDetails(const std::string& accountID,
return false; return false;
} }
try {
if (codec->systemCodecInfo.mediaType & ring::MEDIA_AUDIO) { if (codec->systemCodecInfo.mediaType & ring::MEDIA_AUDIO) {
if (auto foundCodec = std::static_pointer_cast<ring::AccountAudioCodecInfo>(codec)) { if (auto foundCodec = std::static_pointer_cast<ring::AccountAudioCodecInfo>(codec)) {
foundCodec->setCodecSpecifications(details); foundCodec->setCodecSpecifications(details);
...@@ -430,6 +431,10 @@ setCodecDetails(const std::string& accountID, ...@@ -430,6 +431,10 @@ setCodecDetails(const std::string& accountID,
return true; return true;
} }
} }
} catch (const std::exception& e) {
RING_ERR("Cannot set codec specifications: %s", e.what());
}
return false; return false;
} }
......
...@@ -126,10 +126,8 @@ SystemVideoCodecInfo::getCodecSpecifications() ...@@ -126,10 +126,8 @@ SystemVideoCodecInfo::getCodecSpecifications()
}; };
} }
AccountCodecInfo::AccountCodecInfo(const SystemCodecInfo& sysCodecInfo) AccountCodecInfo::AccountCodecInfo(const SystemCodecInfo& sysCodecInfo) noexcept
: systemCodecInfo(sysCodecInfo) : systemCodecInfo(sysCodecInfo)
, order(0)
, isActive(true)
, payloadType(sysCodecInfo.payloadType) , payloadType(sysCodecInfo.payloadType)
, bitrate(sysCodecInfo.bitrate) , bitrate(sysCodecInfo.bitrate)
{ {
...@@ -139,8 +137,31 @@ AccountCodecInfo::AccountCodecInfo(const SystemCodecInfo& sysCodecInfo) ...@@ -139,8 +137,31 @@ AccountCodecInfo::AccountCodecInfo(const SystemCodecInfo& sysCodecInfo)
quality = SystemCodecInfo::DEFAULT_NO_QUALITY; quality = SystemCodecInfo::DEFAULT_NO_QUALITY;
} }
AccountCodecInfo::~AccountCodecInfo() AccountCodecInfo&
{} AccountCodecInfo::operator=(AccountCodecInfo&& o)
{
if (&systemCodecInfo != &o.systemCodecInfo)
throw std::runtime_error("cannot assign codec info object pointing to another codec.");
order = o.order;
isActive = o.isActive;
payloadType = o.payloadType;
bitrate = o.bitrate;
quality = o.quality;
return *this;
}
AccountCodecInfo&
AccountCodecInfo::operator=(const AccountCodecInfo& o)
{
if (&systemCodecInfo != &o.systemCodecInfo)
throw std::runtime_error("cannot assign codec info object pointing to another codec.");
order = o.order;
isActive = o.isActive;
payloadType = o.payloadType;
bitrate = o.bitrate;
quality = o.quality;
return *this;
}
AccountAudioCodecInfo::AccountAudioCodecInfo(const SystemAudioCodecInfo& sysCodecInfo) AccountAudioCodecInfo::AccountAudioCodecInfo(const SystemAudioCodecInfo& sysCodecInfo)
: AccountCodecInfo(sysCodecInfo) : AccountCodecInfo(sysCodecInfo)
...@@ -162,17 +183,13 @@ AccountAudioCodecInfo::getCodecSpecifications() ...@@ -162,17 +183,13 @@ AccountAudioCodecInfo::getCodecSpecifications()
void void
AccountAudioCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details) AccountAudioCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details)
{ {
auto it = details.find(DRing::Account::ConfProperties::CodecInfo::BITRATE); decltype(bitrate) tmp_bitrate = ring::stoi(details.at(DRing::Account::ConfProperties::CodecInfo::BITRATE));
if (it != details.end()) decltype(audioformat) tmp_audioformat = audioformat;
bitrate = ring::stoi(it->second); tmp_audioformat.sample_rate = ring::stoi(details.at(DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE));
it = details.find(DRing::Account::ConfProperties::CodecInfo::SAMPLE_RATE);
if (it != details.end())
audioformat.sample_rate = ring::stoi(it->second);
it = details.find(DRing::Account::ConfProperties::CodecInfo::CHANNEL_NUMBER); // copy back if no exception was raised
if (it != details.end()) bitrate = tmp_bitrate;
audioformat.nb_channels = ring::stoi(it->second); audioformat = tmp_audioformat;
} }
bool bool
...@@ -181,10 +198,6 @@ AccountAudioCodecInfo::isPCMG722() const ...@@ -181,10 +198,6 @@ AccountAudioCodecInfo::isPCMG722() const
return systemCodecInfo.avcodecId == AV_CODEC_ID_ADPCM_G722; return systemCodecInfo.avcodecId == AV_CODEC_ID_ADPCM_G722;
} }
AccountAudioCodecInfo::~AccountAudioCodecInfo()
{}
AccountVideoCodecInfo::AccountVideoCodecInfo(const SystemVideoCodecInfo& sysCodecInfo) AccountVideoCodecInfo::AccountVideoCodecInfo(const SystemVideoCodecInfo& sysCodecInfo)
: AccountCodecInfo(sysCodecInfo) : AccountCodecInfo(sysCodecInfo)
, frameRate(sysCodecInfo.frameRate) , frameRate(sysCodecInfo.frameRate)
...@@ -211,24 +224,26 @@ AccountVideoCodecInfo::getCodecSpecifications() ...@@ -211,24 +224,26 @@ AccountVideoCodecInfo::getCodecSpecifications()
void void
AccountVideoCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details) AccountVideoCodecInfo::setCodecSpecifications(const std::map<std::string, std::string>& details)
{ {
auto copy = *this;
auto it = details.find(DRing::Account::ConfProperties::CodecInfo::BITRATE); auto it = details.find(DRing::Account::ConfProperties::CodecInfo::BITRATE);
if (it != details.end()) if (it != details.end())
bitrate = ring::stoi(it->second); copy.bitrate = ring::stoi(it->second);
it = details.find(DRing::Account::ConfProperties::CodecInfo::FRAME_RATE); it = details.find(DRing::Account::ConfProperties::CodecInfo::FRAME_RATE);
if (it != details.end()) if (it != details.end())
frameRate = ring::stoi(it->second); copy.frameRate = ring::stoi(it->second);
it = details.find(DRing::Account::ConfProperties::CodecInfo::QUALITY); it = details.find(DRing::Account::ConfProperties::CodecInfo::QUALITY);
if (it != details.end()) if (it != details.end())
quality = ring::stoi(it->second); copy.quality = ring::stoi(it->second);
it = details.find(DRing::Account::ConfProperties::CodecInfo::AUTO_QUALITY_ENABLED); it = details.find(DRing::Account::ConfProperties::CodecInfo::AUTO_QUALITY_ENABLED);
if (it != details.end()) if (it != details.end())
isAutoQualityEnabled = (it->second == TRUE_STR) ? true : false; copy.isAutoQualityEnabled = (it->second == TRUE_STR) ? true : false;
}
AccountVideoCodecInfo::~AccountVideoCodecInfo() // copy back if no exception was raised
{} *this = std::move(copy);
}
} // namespace ring } // namespace ring
...@@ -152,12 +152,15 @@ struct SystemVideoCodecInfo : SystemCodecInfo ...@@ -152,12 +152,15 @@ struct SystemVideoCodecInfo : SystemCodecInfo
*/ */
struct AccountCodecInfo struct AccountCodecInfo
{ {
AccountCodecInfo(const SystemCodecInfo& sysCodecInfo); AccountCodecInfo(const SystemCodecInfo& sysCodecInfo) noexcept;
~AccountCodecInfo(); AccountCodecInfo(const AccountCodecInfo&) noexcept = default;
AccountCodecInfo(AccountCodecInfo&&) noexcept = default;
AccountCodecInfo& operator=(const AccountCodecInfo&);
AccountCodecInfo& operator=(AccountCodecInfo&&);
const SystemCodecInfo& systemCodecInfo; const SystemCodecInfo& systemCodecInfo;
unsigned order; /*used to define prefered codec list order in UI*/ unsigned order {0}; /*used to define prefered codec list order in UI*/
bool isActive; bool isActive {true};
/* account custom values */ /* account custom values */
unsigned payloadType; unsigned payloadType;
unsigned bitrate; unsigned bitrate;
...@@ -169,7 +172,6 @@ struct AccountCodecInfo ...@@ -169,7 +172,6 @@ struct AccountCodecInfo
struct AccountAudioCodecInfo : AccountCodecInfo struct AccountAudioCodecInfo : AccountCodecInfo
{ {
AccountAudioCodecInfo(const SystemAudioCodecInfo& sysCodecInfo); AccountAudioCodecInfo(const SystemAudioCodecInfo& sysCodecInfo);
~AccountAudioCodecInfo();
std::map<std::string, std::string> getCodecSpecifications(); std::map<std::string, std::string> getCodecSpecifications();
void setCodecSpecifications(const std::map<std::string, std::string>& details); void setCodecSpecifications(const std::map<std::string, std::string>& details);
...@@ -182,7 +184,6 @@ struct AccountAudioCodecInfo : AccountCodecInfo ...@@ -182,7 +184,6 @@ struct AccountAudioCodecInfo : AccountCodecInfo
struct AccountVideoCodecInfo : AccountCodecInfo struct AccountVideoCodecInfo : AccountCodecInfo
{ {
AccountVideoCodecInfo(const SystemVideoCodecInfo& sysCodecInfo); AccountVideoCodecInfo(const SystemVideoCodecInfo& sysCodecInfo);
~AccountVideoCodecInfo();
void setCodecSpecifications(const std::map<std::string, std::string>& details); void setCodecSpecifications(const std::map<std::string, std::string>& details);
std::map<std::string, std::string> getCodecSpecifications(); std::map<std::string, std::string> getCodecSpecifications();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment