add some more validation

pull/32/head
Geoffrey Merck 4 years ago
parent 6ed2a84873
commit c7e5b5a655

@ -41,5 +41,6 @@ void CAPRSFrame::clear()
m_source.clear();
m_destination.clear();
m_path.clear();
m_body.clear();
m_type = APFT_UNKNOWN;
}

@ -67,7 +67,8 @@ void CAPRSParser::setFrameType(CAPRSFrame& frame)
switch (body[0])
{
case ':':
if(body[10] == ':')
if(body[10] == ':' && std::all_of(body.begin() + 1, body.begin() + 10,
[](char c){ return c == ' ' || c == '-' || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'); }))
type = APFT_MESSAGE;
break;

@ -89,4 +89,17 @@ TEST_F(APRSParser_parseAPRSFrame, CorrectMessageFrameWithoutDigipeater) {
EXPECT_STRCASEEQ(aprsFrame.getSource().c_str(), "N0CALL");
EXPECT_EQ(aprsFrame.getType(), APFT_MESSAGE);
EXPECT_EQ(aprsFrame.getPath().size(), 0);
}
TEST_F(APRSParser_parseAPRSFrame, InvalideMessageFrame) {
CAPRSFrame aprsFrame;
bool retVal = CAPRSParser::parseFrame("N0CALL>APRS::F4ABC&@#$:Test Message", aprsFrame);
EXPECT_FALSE(retVal);
EXPECT_STRCASEEQ(aprsFrame.getBody().c_str(), "");
EXPECT_STRCASEEQ(aprsFrame.getDestination().c_str(), "");
EXPECT_STRCASEEQ(aprsFrame.getSource().c_str(), "");
EXPECT_EQ(aprsFrame.getType(), APFT_UNKNOWN);
EXPECT_EQ(aprsFrame.getPath().size(), 0U);
}
Loading…
Cancel
Save

Powered by TurnKey Linux.