- fixed buffer overflow due to not consumming buffer

git-svn-id: http://moon:8086/svn/software/trunk/libsrc/cpp@1080 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2022-06-24 16:08:14 +00:00
parent d5e1a1d707
commit 607c4ec647
2 changed files with 33 additions and 21 deletions
+30 -18
View File
@@ -39,24 +39,34 @@ void DeFormatter::prepare()
void DeFormatter::process()
{
// Process input
if (m_state == Idle)
while(m_buf_in->len())
{
process_sync();
}
else if (m_state == Header)
{
process_header();
}
else if (m_state == Data)
{
process_data();
bool exit_loop = false;
// Process input
if (m_state == Idle)
{
exit_loop = process_sync();
}
else if (m_state == Header)
{
exit_loop = process_header();
}
else if (m_state == Data)
{
exit_loop = process_data();
}
if (exit_loop)
{
break;
}
}
}
void DeFormatter::process_sync()
bool DeFormatter::process_sync()
{
while(m_buf_in->len())
if(m_buf_in->len())
{
uint8_t data;
m_buf_in->read(&data, 1);
@@ -66,16 +76,16 @@ void DeFormatter::process_sync()
if (m_sync_preamble == 0x55AA)
{
m_state = Header;
break;
}
}
return false;
}
void DeFormatter::process_header()
bool DeFormatter::process_header()
{
if (m_buf_in->len() < sizeof(frame_hdr_t))
{
return;
return true;
}
m_buf_in->read((uint8_t*)&m_Hdr, sizeof(frame_hdr_t));
@@ -85,9 +95,10 @@ void DeFormatter::process_header()
m_scrambler.process((uint8_t*)&m_Hdr.length, sizeof(m_Hdr.length));
m_dataCount = 0;
m_state = Data;
return false;
}
void DeFormatter::process_data()
bool DeFormatter::process_data()
{
if (m_Hdr.length != sizeof(m_data))
{
@@ -96,7 +107,7 @@ void DeFormatter::process_data()
if(m_buf_in->len() < m_Hdr.length)
{
return;
return true;
}
m_buf_in->read(m_data, m_Hdr.length);
@@ -118,6 +129,7 @@ void DeFormatter::process_data()
m_frameStats.numTotalFrame++;
m_dataCount = 0;
m_state = Idle;
return false;
}
// --------------------------------------------------------------
+3 -3
View File
@@ -40,9 +40,9 @@ private:
Processor::Buffer<uint8_t> *m_buf_in;
Processor::Buffer<uint8_t> *m_buf_out;
void process_sync();
void process_header();
void process_data();
bool process_sync();
bool process_header();
bool process_data();
};
// --------------------------------------------------------------