Merge pull request #8186

f68f927 Undefined behaviour fixes (SChernykh)
This commit is contained in:
luigi1111 2022-03-18 16:31:18 -05:00
commit 6a0d973dc9
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
6 changed files with 24 additions and 12 deletions

View file

@ -48,7 +48,7 @@ namespace levin
{
uint64_t m_signature;
uint64_t m_cb;
bool m_have_to_return_data;
uint8_t m_have_to_return_data;
uint32_t m_command;
int32_t m_return_code;
uint32_t m_reservedA; //probably some flags in future
@ -63,7 +63,7 @@ namespace levin
{
uint64_t m_signature;
uint64_t m_cb;
bool m_have_to_return_data;
uint8_t m_have_to_return_data;
uint32_t m_command;
int32_t m_return_code;
uint32_t m_flags;

View file

@ -82,7 +82,7 @@ int levin_client_impl::invoke(int command, const epee::span<const uint8_t> in_bu
bucket_head head = {0};
head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = true;
head.m_have_to_return_data = 1;
head.m_command = SWAP32LE(command);
if(!m_transport.send(&head, sizeof(head)))
return -1;
@ -118,7 +118,7 @@ int levin_client_impl::notify(int command, const std::string& in_buff)
bucket_head head = {0};
head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = false;
head.m_have_to_return_data = 0;
head.m_command = SWAP32LE(command);
if(!m_transport.send((const char*)&head, sizeof(head)))
@ -141,7 +141,7 @@ inline
bucket_head2 head = {0};
head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = true;
head.m_have_to_return_data = 1;
head.m_command = SWAP32LE(command);
head.m_return_code = SWAP32LE(0);
head.m_flags = SWAP32LE(LEVIN_PACKET_REQUEST);
@ -179,7 +179,7 @@ inline
bucket_head2 head = {0};
head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = false;
head.m_have_to_return_data = 0;
head.m_command = SWAP32LE(command);
head.m_return_code = SWAP32LE(0);
head.m_flags = SWAP32LE(LEVIN_PACKET_REQUEST);

View file

@ -242,7 +242,7 @@ namespace levin
bucket_head head = {0};
head.m_signature = LEVIN_SIGNATURE;
head.m_cb = in_buff.size();
head.m_have_to_return_data = true;
head.m_have_to_return_data = 1;
head.m_id = target;
#ifdef TRACE_LEVIN_PACKETS_BY_GUIDS
::UuidCreate(&head.m_id);
@ -320,7 +320,7 @@ namespace levin
bucket_head head = {0};
head.m_signature = LEVIN_SIGNATURE;
head.m_cb = in_buff.size();
head.m_have_to_return_data = false;
head.m_have_to_return_data = 0;
head.m_id = target;
#ifdef TRACE_LEVIN_PACKETS_BY_GUIDS
::UuidCreate(&head.m_id);
@ -510,7 +510,7 @@ namespace levin
head.m_cb = return_buff.size();
head.m_have_to_return_data = false;
head.m_have_to_return_data = 0;
head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
head.m_flags = LEVIN_PACKET_RESPONSE;

View file

@ -46,7 +46,7 @@ namespace levin
levin::bucket_head& head = *(levin::bucket_head*)(&buff[0]);
head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
head.m_cb = 0;
head.m_have_to_return_data = true;
head.m_have_to_return_data = 1;
head.m_command = SWAP32LE(command_id);
head.m_return_code = SWAP32LE(1);
head.m_reservedA = rand(); //probably some flags in future
@ -68,7 +68,7 @@ namespace levin
levin::bucket_head& head = *(levin::bucket_head*)(&buff[0]);
head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
head.m_cb = 0;
head.m_have_to_return_data = true;
head.m_have_to_return_data = 1;
head.m_command = SWAP32LE(command_id);
head.m_return_code = SWAP32LE(1);
head.m_reservedA = rand(); //probably some flags in future

View file

@ -156,7 +156,7 @@ namespace levin
std::string return_buff;
m_current_head.m_return_code = m_config.m_pcommands_handler->invoke(m_current_head.m_command, buff_to_invoke, return_buff, m_conn_context);
m_current_head.m_cb = return_buff.size();
m_current_head.m_have_to_return_data = false;
m_current_head.m_have_to_return_data = 0;
return_buff.insert(0, (const char*)&m_current_head, sizeof(m_current_head));
if(!m_psnd_hndlr->do_send(byte_slice{std::move(return_buff)}))

View file

@ -157,6 +157,18 @@ namespace epee
pod_val = CONVERT_POD(pod_val);
}
template<>
void throwable_buffer_reader::read<bool>(bool& pod_val)
{
RECURSION_LIMITATION();
static_assert(std::is_pod<bool>::value, "POD type expected");
static_assert(sizeof(bool) == sizeof(uint8_t), "We really shouldn't use bool directly in serialization code. Replace it with uint8_t if this assert triggers!");
uint8_t t;
read(&t, sizeof(t));
CHECK_AND_ASSERT_THROW_MES(t <= 1, "Invalid bool value " << t);
pod_val = (t != 0);
}
template<class t_type>
t_type throwable_buffer_reader::read()
{