Harden agains network packet overruns

Patch by NickyD from Firestorm
This commit is contained in:
Latif Khalifa
2013-09-26 04:09:01 +02:00
parent 3066dcac58
commit 6c1ea557b5
3 changed files with 38 additions and 7 deletions

View File

@@ -201,9 +201,17 @@ inline BOOL LLDataPackerBinaryBuffer::verifyLength(const S32 data_size, const ch
{
if (mWriteEnabled && (mCurBufferp - mBufferp) > mBufferSize - data_size)
{
llwarns << "Buffer overflow in BinaryBuffer length verify, field name " << name << "!" << llendl;
llwarns << "Current pos: " << (int)(mCurBufferp - mBufferp) << " Buffer size: " << mBufferSize << " Data size: " << data_size << llendl;
return FALSE;
// <FS:ND> Handle invalid packets by throwing an exception and a graceful continue
// llwarns << "Buffer overflow in BinaryBuffer length verify, field name " << name << "!" << llendl;
// llwarns << "Current pos: " << (int)(mCurBufferp - mBufferp) << " Buffer size: " << mBufferSize << " Data size: " << data_size << llendl;
// return FALSE;
std::stringstream strm;
strm << "Buffer overflow in BinaryBuffer length verify, field name " << name << "!" << std::endl;
strm << "Current pos: " << (int)(mCurBufferp - mBufferp) << " Buffer size: " << mBufferSize << " Data size: " << data_size << std::endl;
throw std::string( strm.str() );
// </FS:ND>
}
return TRUE;

View File

@@ -364,7 +364,22 @@ public:
{
if (mHandlerFunc)
{
// <FS:ND> Handle invalid packets by throwing an exception and a graceful continue
// mHandlerFunc(msgsystem, mUserData);
try
{
mHandlerFunc(msgsystem, mUserData);
}
catch( std::string &why )
{
llwarns << why << llendl;
}
// </FS:ND>
return TRUE;
}
return FALSE;

View File

@@ -511,21 +511,29 @@ BOOL LLTemplateMessageReader::decodeTemplate(
void LLTemplateMessageReader::logRanOffEndOfPacket( const LLHost& host, const S32 where, const S32 wanted )
{
// <FS:ND> Handle invalid packets by throwing an exception and a graceful continue
// we've run off the end of the packet!
llwarns << "Ran off end of packet " << mCurrentRMessageTemplate->mName
std::stringstream strm;
// llwarns << "Ran off end of packet " << mCurrentRMessageTemplate->mName
strm << "Ran off end of packet " << mCurrentRMessageTemplate->mName
// << " with id " << mCurrentRecvPacketID
<< " from " << host
<< " trying to read " << wanted
<< " bytes at position " << where
<< " going past packet end at " << mReceiveSize
<< llendl;
// << llendl;
<< std::endl;
if(gMessageSystem->mVerboseLog)
{
llinfos << "MSG: -> " << host << "\tREAD PAST END:\t"
// llinfos << "MSG: -> " << host << "\tREAD PAST END:\t"
strm << "MSG: -> " << host << "\tREAD PAST END:\t"
// << mCurrentRecvPacketID << " "
<< getMessageName() << llendl;
// << getMessageName() << llendl;
<< getMessageName() << std::endl;
}
gMessageSystem->callExceptionFunc(MX_RAN_OFF_END_OF_PACKET);
throw std::string( strm.str() );
}
static LLFastTimer::DeclareTimer FTM_PROCESS_MESSAGES("Process Messages");