1
0
Fork 0

Add sanity checks to the DTMF code.

ycs232-kbc
Jonathan Naylor 7 years ago
parent c85aa2c9f3
commit 253af16694

@ -166,6 +166,9 @@ WX_STATUS CDTMF::decodeVDMode2Slice(unsigned char* ambe, bool end)
WX_STATUS CDTMF::validate() const WX_STATUS CDTMF::validate() const
{ {
if (m_command.empty())
return WXS_NONE;
size_t length = m_command.length(); size_t length = m_command.length();
char first = m_command.at(0U); char first = m_command.at(0U);
@ -173,21 +176,24 @@ WX_STATUS CDTMF::validate() const
return WXS_DISCONNECT; return WXS_DISCONNECT;
} else if (length == 3U && first == 'A') { } else if (length == 3U && first == 'A') {
for (unsigned int i = 1U; i < 3U; i++) { for (unsigned int i = 1U; i < 3U; i++) {
if (m_command.at(i) < '0' || m_command.at(i) > '9') char c = m_command.at(i);
if (c < '0' || c > '9')
return WXS_NONE; return WXS_NONE;
} }
return WXS_CONNECT_FCS; return WXS_CONNECT_FCS;
} else if (length == 4U && first == 'A') { } else if (length == 4U && first == 'A') {
for (unsigned int i = 1U; i < 4U; i++) { for (unsigned int i = 1U; i < 4U; i++) {
if (m_command.at(i) < '0' || m_command.at(i) > '9') char c = m_command.at(i);
if (c < '0' || c > '9')
return WXS_NONE; return WXS_NONE;
} }
return WXS_CONNECT_FCS; return WXS_CONNECT_FCS;
} else if (length == 6U && first == '#') { } else if (length == 6U && first == '#') {
for (unsigned int i = 1U; i < 6U; i++) { for (unsigned int i = 1U; i < 6U; i++) {
if (m_command.at(i) < '0' || m_command.at(i) > '9') char c = m_command.at(i);
if (c < '0' || c > '9')
return WXS_NONE; return WXS_NONE;
} }
@ -205,6 +211,9 @@ std::string CDTMF::getReflector()
std::string command = m_command; std::string command = m_command;
reset(); reset();
if (command.empty())
return "";
return command.substr(1U); return command.substr(1U);
} }

Loading…
Cancel
Save