Merge pull request #1879 from G10h4ck/item_uninitialized_ptr

RawMemoryWrapper::serial_process report error
This commit is contained in:
csoler 2020-04-27 23:24:09 +02:00 committed by GitHub
commit 59b7f042e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -542,28 +542,33 @@ void RsTypeSerializer::RawMemoryWrapper::serial_process(
ctx.mOffset += second; ctx.mOffset += second;
break; break;
case RsGenericSerializer::DESERIALIZE: case RsGenericSerializer::DESERIALIZE:
if(first || second)
{ {
// In case first,second is not properly initialized, we set them to nullptr,0 /* Items are created anew before deserialization so buffer pointer
first = nullptr; * must be null and size 0 at this point */
second = 0;
uint32_t serialSize = 0; RsWarn() << __PRETTY_FUNCTION__ << " DESERIALIZE got uninitialized "
RS_SERIAL_PROCESS(serialSize); << " or pre-allocated buffer! Buffer pointer: " << first
<< " must be null and size: " << second << " must be 0 at "
<< "this point. Does your item costructor initialize them "
<< "properly?" << std::endl;
print_stacktrace();
}
RS_SERIAL_PROCESS(second);
if(!ctx.mOk) break; if(!ctx.mOk) break;
ctx.mOk = (serialSize <= MAX_SERIALIZED_CHUNK_SIZE); ctx.mOk = (second <= MAX_SERIALIZED_CHUNK_SIZE);
if(!ctx.mOk) if(!ctx.mOk)
{ {
RsErr() << __PRETTY_FUNCTION__ RsErr() << __PRETTY_FUNCTION__
<< std::errc::message_size << " " << std::errc::message_size << " "
<< serialSize << " > " << MAX_SERIALIZED_CHUNK_SIZE << second << " > " << MAX_SERIALIZED_CHUNK_SIZE
<< std::endl; << std::endl;
clear(); clear();
break; break;
} }
if(!serialSize) if(!second)
{ {
Dbg3() << __PRETTY_FUNCTION__ << " Deserialized empty memory chunk" Dbg3() << __PRETTY_FUNCTION__ << " Deserialized empty memory chunk"
<< std::endl; << std::endl;
@ -571,25 +576,21 @@ void RsTypeSerializer::RawMemoryWrapper::serial_process(
break; break;
} }
ctx.mOk = (ctx.mSize >= ctx.mOffset + serialSize); ctx.mOk = ctx.mSize >= ctx.mOffset + second;
if(!ctx.mOk) if(!ctx.mOk)
{ {
RsErr() << __PRETTY_FUNCTION__ << std::errc::no_buffer_space << std::endl; RsErr() << __PRETTY_FUNCTION__ << std::errc::no_buffer_space
<< std::endl;
print_stacktrace(); print_stacktrace();
clear(); clear();
break; break;
} }
first = reinterpret_cast<uint8_t*>(malloc(serialSize)); first = reinterpret_cast<uint8_t*>(malloc(second));
second = serialSize; memcpy(first, ctx.mData + ctx.mOffset, second);
ctx.mOffset += second;
memcpy(first, ctx.mData + ctx.mOffset, serialSize);
ctx.mOffset += serialSize;
break; break;
}
case RsGenericSerializer::PRINT: break; case RsGenericSerializer::PRINT: break;
case RsGenericSerializer::TO_JSON: case RsGenericSerializer::TO_JSON:
{ {