Skip to content

Commit 697e3de

Browse files
Merge pull request #401 from SailCast/master
Fix for invalid length GetVarStr
2 parents c0e04c3 + db97467 commit 697e3de

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/N2kMsg.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,10 @@ bool tN2kMsg::GetStr(size_t StrBufSize, char *StrBuf, size_t Length, unsigned ch
415415

416416
//*****************************************************************************
417417
bool tN2kMsg::GetVarStr(size_t &StrBufSize, char *StrBuf, int &Index) const {
418-
size_t Len=GetByte(Index)-2;
418+
size_t Len=GetByte(Index);
419419
uint8_t Type=GetByte(Index);
420+
if ( Len<2) { StrBufSize=0; return false; } // invalid length
421+
Len-=2;
420422
if ( Type!=0x01 ) { StrBufSize=0; return false; }
421423
if ( StrBuf!=0 ) {
422424
GetStr(StrBufSize,StrBuf,Len,0xff,Index);

0 commit comments

Comments
 (0)