RetroShare/libretroshare/src/chat/rschatitems.cc
Gioacchino Mazzurco 0d1524aa12
Fix crash due to RsChatAvatarItem uninitialized pointer
Caught signal 11 (SIGSEGV)
stack trace:
retroshare( 0xbbd2da)[0x558ccf46a2da]
retroshare(CrashStackTrace::abortHandler(int) 0xeb)[0x558ccf471c5c]
/lib64/libc.so.6( 0x38f80)[0x7f6ef6facf80]
/lib64/libc.so.6(realloc 0x54)[0x7f6ef6fffef4]
retroshare(RsTypeSerializer::RawMemoryWrapper::serial_process(RsGenericSerializer::SerializeJob, RsGenericSerializer::SerializeContext&) 0x5d4)[0x558ccfcddad0]
retroshare(std::enable_if<std::is_base_of<RsSerializable, RsTypeSerializer::RawMemoryWrapper>::value, void>::type RsTypeSerializer::serial_process<RsTypeSerializer::RawMemoryWrapper>(RsGenericSerializer::SerializeJob, RsGenericSerializer::SerializeContext&, RsTypeSerializer::RawMemoryWrapper&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) 0x9d)[0x558ccfb3da66]
retroshare(RsChatAvatarItem::serial_process(RsGenericSerializer::SerializeJob, RsGenericSerializer::SerializeContext&) 0x84)[0x558ccff90ba6]
retroshare(RsServiceSerializer::deserialise(void*, unsigned int*) 0x403)[0x558ccfcd96e9]
retroshare(RsSerialiser::deserialise(void*, unsigned int*) 0x38e)[0x558ccfb5a1a8]
retroshare(pqiSSLstore::readPkt(RsItem**) 0x3f9)[0x558ccfad329f]
retroshare(pqiSSLstore::GetItem() 0xbb)[0x558ccfad2d9f]
retroshare(pqiSSLstore::getEncryptedItems(std::__cxx11::list<RsItem*, std::allocator<RsItem*> >&) 0x3e)[0x558ccfad2c26]
retroshare(p3Config::loadAttempt(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::list<RsItem*, std::allocator<RsItem*> >&) 0xf8)[0x558ccfab20d0]
retroshare(p3Config::loadConfig() 0xeb)[0x558ccfab1d69]
retroshare(p3Config::loadConfiguration(t_RsGenericIdType<20u, false, (RsGenericIdType)2>&) 0x1c)[0x558ccfab1c7c]
retroshare(p3ConfigMgr::loadConfig() 0x97)[0x558ccfab17f3]
retroshare(p3ConfigMgr::loadConfiguration() 0x18)[0x558ccfab1758]
retroshare(RsServer::StartupRetroShare() 0x4407)[0x558ccfb02fab]
retroshare(main 0x17e2)[0x558ccf46d291]
/lib64/libc.so.6(__libc_start_main 0xeb)[0x7f6ef6f97e9b]
retroshare(_start 0x2a)[0x558ccf438c9a]
D 1585687209 void RetroDb::closeDb() sqlite3_close return: 0
D 1585687209 void RetroDb::closeDb() sqlite3_close return: 0
Memory still in use at end of program: 24776 bytes.
2020-04-14 12:17:03 +02:00

206 lines
9.8 KiB
C++

/*******************************************************************************
* libretroshare/src/chat: rschatitems.cc *
* *
* libretroshare: retroshare core library *
* *
* Copyright 2007-2008 by Robert Fernie. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include <stdexcept>
#include "retroshare/rsmsgs.h"
#include "util/rstime.h"
#include "serialiser/rsbaseserial.h"
#include "serialiser/rstlvbase.h"
#include "serialiser/rstypeserializer.h"
#include "chat/rschatitems.h"
//#define CHAT_DEBUG 1
//static const uint32_t RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE = 0x0001;
RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id) const
{
if(service_id != RS_SERVICE_TYPE_CHAT) return NULL;
switch(item_sub_id)
{
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem();
case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem();
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem();
case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem();
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem();
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE: return new RsChatLobbyInviteItem();
case RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE_DEPRECATED: return new RsChatLobbyInviteItem_Deprecated(); // to be removed (deprecated since May 2017)
case RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE: return new RsChatLobbyConnectChallengeItem();
case RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE: return new RsChatLobbyUnsubscribeItem();
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT: return new RsChatLobbyEventItem();
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST: return new RsChatLobbyListRequestItem();
case RS_PKT_SUBTYPE_CHAT_LOBBY_LIST: return new RsChatLobbyListItem();
case RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG: return new RsChatLobbyConfigItem();
case RS_PKT_SUBTYPE_SUBSCRIBED_CHAT_LOBBY_CONFIG: return new RsSubscribedChatLobbyConfigItem();
case RS_PKT_SUBTYPE_OUTGOING_MAP: return new PrivateOugoingMapItem();
default:
std::cerr << "Unknown packet type in chat!" << std::endl;
return NULL;
}
}
void RsChatMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ;
RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,message,"message") ;
}
/*************************************************************************/
void RsChatLobbyBouncingObject::serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ;
RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,nick,"nick") ;
if(!(ctx.mFlags & RsSerializationFlags::SIGNATURE))
RS_SERIAL_PROCESS(signature);
}
void RsChatLobbyMsgItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsChatMsgItem::serial_process(j,ctx) ;
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
RsChatLobbyBouncingObject::serial_process(j,ctx) ;
}
void RsChatLobbyListRequestItem::serial_process(RsGenericSerializer::SerializeJob /*j*/,RsGenericSerializer::SerializeContext& /*ctx*/)
{
// nothing to do. This is an empty item.
}
template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& /*name*/)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,info.id,"info.id") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,info.name, "info.name") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,info.topic,"info.topic") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx, info.count,"info.count") ;
RsTypeSerializer::serial_process (j,ctx, info.flags,"info.flags") ;
}
void RsChatLobbyListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ;
}
void RsChatLobbyEventItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint8_t>(j,ctx,event_type,"event_type") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,string1,"string1") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime ,"sendTime") ;
RsChatLobbyBouncingObject::serial_process(j,ctx) ;
}
void RsChatLobbyUnsubscribeItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_id,"lobby_id") ;
}
void RsChatLobbyConnectChallengeItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,challenge_code,"challenge_code") ;
}
// to be removed (deprecated since May 2017)
void RsChatLobbyInviteItem_Deprecated::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx, lobby_id, "lobby_id") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ;
RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ;
}
void RsChatLobbyInviteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx, lobby_id, "lobby_id") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_name, "lobby_name") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_NAME,lobby_topic,"lobby_topic") ;
RsTypeSerializer::serial_process (j,ctx, lobby_flags,"lobby_flags") ;
}
void RsPrivateChatMsgConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
uint32_t x=0 ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx, x, "place holder value") ;
RsTypeSerializer::serial_process (j,ctx, configPeerId,"configPeerId") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx, chatFlags, "chatFlags") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx, sendTime, "sendTime") ;
RsTypeSerializer::serial_process (j,ctx,TLV_TYPE_STR_MSG,message, "message") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx, recvTime, "recvTime") ;
}
void RsChatStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,flags,"flags") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,status_string,"status_string") ;
}
void RsChatAvatarItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::TlvMemBlock_proxy b(image_data,image_size) ;
RsTypeSerializer::serial_process(j,ctx,b,"image data") ;
}
void RsSubscribedChatLobbyConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
info.serial_process(j,ctx);
}
void RsChatLobbyConfigItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_Id,"lobby_Id") ;
RsTypeSerializer::serial_process(j,ctx,flags,"flags") ;
}
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const RsPeerId& /*peerId*/, uint32_t confFlags)
{
PeerId(ci->PeerId());
configPeerId = ci->PeerId();
chatFlags = ci->chatFlags;
configFlags = confFlags;
sendTime = ci->sendTime;
message = ci->message;
recvTime = ci->recvTime;
}
/* get data from RsPrivateChatMsgConfigItem to RsChatMsgItem */
void RsPrivateChatMsgConfigItem::get(RsChatMsgItem *ci)
{
ci->PeerId(configPeerId);
ci->chatFlags = chatFlags;
//configFlags not used
ci->sendTime = sendTime;
ci->message = message;
ci->recvTime = recvTime;
}
void PrivateOugoingMapItem::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{ RS_SERIAL_PROCESS(store); }