fixed dangerous memcpy in RsTurtleGenericSearchResultItem::clone() function

This commit is contained in:
csoler 2018-10-12 22:19:07 +02:00
parent 18eee374f1
commit 9c90b32def
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
2 changed files with 14 additions and 9 deletions

View File

@ -100,15 +100,20 @@ void RsTurtleGenericSearchRequestItem::serial_process(RsGenericSerializer::Seria
}
RsTurtleSearchRequestItem *RsTurtleGenericSearchRequestItem::clone() const
{
RsTurtleGenericSearchRequestItem *sr = new RsTurtleGenericSearchRequestItem ;
memcpy(sr,this,sizeof(RsTurtleGenericSearchRequestItem)) ;
sr->search_data = (unsigned char*)rs_malloc(search_data_len) ;
memcpy(sr->search_data,search_data,search_data_len) ;
return sr ;
return new RsTurtleGenericSearchRequestItem(*this) ;
}
RsTurtleGenericSearchRequestItem::RsTurtleGenericSearchRequestItem(const RsTurtleGenericSearchRequestItem& it)
: RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_GENERIC_SEARCH_REQUEST)
{
search_data_len = it.search_data_len ;
search_data = (unsigned char*)rs_malloc(it.search_data_len) ;
service_id = it.service_id ;
request_type = it.request_type ;
memcpy(search_data,it.search_data,it.search_data_len) ;
}
template<> uint32_t RsTypeSerializer::serial_size(const RsRegularExpression::LinearizedExpression& r)
{
uint32_t s = 0 ;

View File

@ -185,7 +185,7 @@ class RsTurtleGenericSearchRequestItem: public RsTurtleSearchRequestItem
void serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx);
private:
RsTurtleGenericSearchRequestItem(const RsTurtleGenericSearchRequestItem&): RsTurtleSearchRequestItem(RS_TURTLE_SUBTYPE_GENERIC_SEARCH_REQUEST) {} // make the object non copi-able.
RsTurtleGenericSearchRequestItem(const RsTurtleGenericSearchRequestItem&); // make the object non copi-able.
RsTurtleGenericSearchRequestItem& operator=(const RsTurtleGenericSearchRequestItem&) { return *this;}
};
class RsTurtleSearchResultItem: public RsTurtleItem