Corrected the MS/TP capture to limit data to the input buffer.

This commit is contained in:
skarg
2008-10-27 19:53:11 +00:00
parent fb72214f83
commit 4dd074630b
4 changed files with 17 additions and 10 deletions
+8 -6
View File
@@ -165,7 +165,8 @@ static void snap_received_packet(
{
uint16_t mtu_len = 0; /* number of octets of packet saved in file */
unsigned i = 0; /* counter */
static uint8_t mtu[1500] = { 0 };
static uint8_t mtu[1500] = { 0 };
size_t max_data = 0;
mtu[0] = 0;
mtu[1] = 0;
@@ -198,13 +199,14 @@ static void snap_received_packet(
mtu[29] = LO_BYTE(mstp_port->DataLength);
mtu[30] = mstp_port->HeaderCRCActual;
mtu_len = 31;
if (mstp_port->DataLength) {
for (i = 0; i < mstp_port->DataLength; i++) {
if (mstp_port->DataLength) {
max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength);
for (i = 0; i < max_data; i++) {
mtu[31 + i] = mstp_port->InputBuffer[i];
}
mtu[31 + mstp_port->DataLength] = mstp_port->DataCRCActualMSB;
mtu[31 + mstp_port->DataLength + 1] = mstp_port->DataCRCActualLSB;
mtu_len += (mstp_port->DataLength + 2);
mtu[31 + max_data] = mstp_port->DataCRCActualMSB;
mtu[31 + max_data + 1] = mstp_port->DataCRCActualLSB;
mtu_len += (max_data + 2);
}
/* Ethernet length is data only - not address or length bytes */
encode_unsigned16(&mtu[12], mtu_len - 14);