Skip to content

Commit 971a934

Browse files
authored
Merge pull request #251 from LeeLeahy2/rtcm-length
Validate the RTCM length field
2 parents 18428f7 + ade9d05 commit 971a934

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ bool ntripServerRtcmMessage(uint8_t data)
180180

181181
switch (ntripServerCrcState)
182182
{
183+
//Read the upper two bits of the length
184+
case RTCM_TRANSPORT_STATE_READ_LENGTH_1:
185+
if (!(data & 3))
186+
{
187+
length = data << 8;
188+
crcState = RTCM_TRANSPORT_STATE_READ_LENGTH_2;
189+
break;
190+
}
191+
192+
//Wait for the preamble byte
193+
crcState = RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3;
194+
195+
//Fall through
196+
// |
197+
// |
198+
// V
199+
183200
//Wait for the preamble byte (0xd3)
184201
case RTCM_TRANSPORT_STATE_WAIT_FOR_PREAMBLE_D3:
185202
sendMessage = false;
@@ -190,12 +207,6 @@ bool ntripServerRtcmMessage(uint8_t data)
190207
}
191208
break;
192209

193-
//Read the upper two bits of the length
194-
case RTCM_TRANSPORT_STATE_READ_LENGTH_1:
195-
length = data << 8;
196-
ntripServerCrcState = RTCM_TRANSPORT_STATE_READ_LENGTH_2;
197-
break;
198-
199210
//Read the lower 8 bits of the length
200211
case RTCM_TRANSPORT_STATE_READ_LENGTH_2:
201212
length |= data;

0 commit comments

Comments
 (0)