mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-04 17:15:31 -05:00
fixed deserialiser for rawWrapper causing crashes when wrapper memory is not initialized properly by the client
This commit is contained in:
parent
86897b60de
commit
76e9387467
@ -543,10 +543,16 @@ void RsTypeSerializer::RawMemoryWrapper::serial_process(
|
|||||||
break;
|
break;
|
||||||
case RsGenericSerializer::DESERIALIZE:
|
case RsGenericSerializer::DESERIALIZE:
|
||||||
{
|
{
|
||||||
|
// In case first,second is not properly initialized, we set them to nullptr,0
|
||||||
|
first = nullptr;
|
||||||
|
second = 0;
|
||||||
|
|
||||||
uint32_t serialSize = 0;
|
uint32_t serialSize = 0;
|
||||||
RS_SERIAL_PROCESS(serialSize);
|
RS_SERIAL_PROCESS(serialSize);
|
||||||
|
|
||||||
if(!ctx.mOk) break;
|
if(!ctx.mOk) break;
|
||||||
ctx.mOk = serialSize <= MAX_SERIALIZED_CHUNK_SIZE;
|
ctx.mOk = (serialSize <= MAX_SERIALIZED_CHUNK_SIZE);
|
||||||
|
|
||||||
if(!ctx.mOk)
|
if(!ctx.mOk)
|
||||||
{
|
{
|
||||||
RsErr() << __PRETTY_FUNCTION__
|
RsErr() << __PRETTY_FUNCTION__
|
||||||
@ -565,25 +571,23 @@ void RsTypeSerializer::RawMemoryWrapper::serial_process(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.mOk = ctx.mSize >= ctx.mOffset + serialSize;
|
ctx.mOk = (ctx.mSize >= ctx.mOffset + serialSize);
|
||||||
|
|
||||||
if(!ctx.mOk)
|
if(!ctx.mOk)
|
||||||
{
|
{
|
||||||
RsErr() << __PRETTY_FUNCTION__ << std::errc::no_buffer_space
|
RsErr() << __PRETTY_FUNCTION__ << std::errc::no_buffer_space << std::endl;
|
||||||
<< std::endl;
|
|
||||||
print_stacktrace();
|
print_stacktrace();
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(serialSize != second)
|
first = reinterpret_cast<uint8_t*>(malloc(serialSize));
|
||||||
{
|
second = serialSize;
|
||||||
first = reinterpret_cast<uint8_t*>(realloc(first, serialSize));
|
|
||||||
second = serialSize;
|
memcpy(first, ctx.mData + ctx.mOffset, serialSize);
|
||||||
}
|
ctx.mOffset += serialSize;
|
||||||
|
|
||||||
memcpy(first, ctx.mData + ctx.mOffset, second);
|
|
||||||
ctx.mOffset += second;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RsGenericSerializer::PRINT: break;
|
case RsGenericSerializer::PRINT: break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user