Prevent reading past message buffers and crashing then.

master
Nicky 2012-12-21 20:28:50 +01:00
parent 07e263e854
commit 302557b4fa
3 changed files with 52 additions and 8 deletions

View File

@ -199,9 +199,18 @@ 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 AsciiBuffer 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

@ -365,7 +365,22 @@ public:
if (mHandlerFunc)
{
LLPerfBlock msg_cb_time("msg_cb", mName);
mHandlerFunc(msgsystem, mUserData);
// <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

@ -508,21 +508,41 @@ 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
// llwarns << "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;
// if(gMessageSystem->mVerboseLog)
// {
// llinfos << "MSG: -> " << host << "\tREAD PAST END:\t"
// // << mCurrentRecvPacketID << " "
// << getMessageName() << llendl;
// }
// gMessageSystem->callExceptionFunc(MX_RAN_OFF_END_OF_PACKET);
std::stringstream strm;
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;
<< std::endl;
if(gMessageSystem->mVerboseLog)
{
llinfos << "MSG: -> " << host << "\tREAD PAST END:\t"
strm << "MSG: -> " << host << "\tREAD PAST END:\t"
// << mCurrentRecvPacketID << " "
<< 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");