mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
refactor: Allow NULL pointers for byte arrays in events.
Some events, notably the file chunk recv one, can give NULL pointers to the client. Not sure they should, but that's what happens, so we support it.
This commit is contained in:
parent
5e2c8cabc1
commit
e7fb91ddb8
|
@ -1 +1 @@
|
|||
030f7ea99c34523091b268df0ea8fb02e81ee340d608af85d502bace4817d6b0 /usr/local/bin/tox-bootstrapd
|
||||
4384074ef96cf8f1ed3c420a58b7f67a49a4e22ad5b8fe1d66a4bddf61235fce /usr/local/bin/tox-bootstrapd
|
||||
|
|
|
@ -216,7 +216,17 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
|||
// gen setters and getters
|
||||
for (const auto& t : event_types) {
|
||||
// setter
|
||||
f << "non_null()\n";
|
||||
std::visit(
|
||||
overloaded{
|
||||
[&](const EventTypeTrivial& t) {
|
||||
f << "non_null()\n";
|
||||
},
|
||||
[&](const EventTypeByteRange& t) {
|
||||
f << "non_null(1) nullable(2)\n";
|
||||
}
|
||||
},
|
||||
t
|
||||
);
|
||||
f << "static " << (t.index() == 0 ? "void" : "bool") << " tox_event_" << event_name_l << "_set_";
|
||||
std::visit(
|
||||
overloaded{
|
||||
|
@ -254,6 +264,9 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
|
|||
f << " " << event_name_l << "->" << t.name_data << " = nullptr;\n";
|
||||
f << " " << event_name_l << "->" << t.name_length << " = 0;\n";
|
||||
f << " }\n\n";
|
||||
f << " if (" << t.name_data << " == nullptr) {\n";
|
||||
f << " assert(" << t.name_length << " == 0);\n";
|
||||
f << " return true;\n }\n\n";
|
||||
f << " uint8_t *" << t.name_data << "_copy = (uint8_t *)malloc(" << t.name_length << ");\n\n";
|
||||
f << " if (" << t.name_data << "_copy == nullptr) {\n";
|
||||
f << " return false;\n }\n\n";
|
||||
|
|
|
@ -58,7 +58,7 @@ Tox_Conference_Type tox_event_conference_invite_get_type(const Tox_Event_Confere
|
|||
return conference_invite->type;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_conference_invite_set_cookie(Tox_Event_Conference_Invite *conference_invite,
|
||||
const uint8_t *cookie, uint32_t cookie_length)
|
||||
{
|
||||
|
@ -70,6 +70,11 @@ static bool tox_event_conference_invite_set_cookie(Tox_Event_Conference_Invite *
|
|||
conference_invite->cookie_length = 0;
|
||||
}
|
||||
|
||||
if (cookie == nullptr) {
|
||||
assert(cookie_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *cookie_copy = (uint8_t *)malloc(cookie_length);
|
||||
|
||||
if (cookie_copy == nullptr) {
|
||||
|
|
|
@ -72,7 +72,7 @@ Tox_Message_Type tox_event_conference_message_get_type(const Tox_Event_Conferenc
|
|||
return conference_message->type;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_conference_message_set_message(Tox_Event_Conference_Message *conference_message,
|
||||
const uint8_t *message, uint32_t message_length)
|
||||
{
|
||||
|
@ -84,6 +84,11 @@ static bool tox_event_conference_message_set_message(Tox_Event_Conference_Messag
|
|||
conference_message->message_length = 0;
|
||||
}
|
||||
|
||||
if (message == nullptr) {
|
||||
assert(message_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *message_copy = (uint8_t *)malloc(message_length);
|
||||
|
||||
if (message_copy == nullptr) {
|
||||
|
|
|
@ -56,7 +56,7 @@ uint32_t tox_event_conference_peer_name_get_peer_number(const Tox_Event_Conferen
|
|||
return conference_peer_name->peer_number;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_conference_peer_name_set_name(Tox_Event_Conference_Peer_Name *conference_peer_name,
|
||||
const uint8_t *name, uint32_t name_length)
|
||||
{
|
||||
|
@ -68,6 +68,11 @@ static bool tox_event_conference_peer_name_set_name(Tox_Event_Conference_Peer_Na
|
|||
conference_peer_name->name_length = 0;
|
||||
}
|
||||
|
||||
if (name == nullptr) {
|
||||
assert(name_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *name_copy = (uint8_t *)malloc(name_length);
|
||||
|
||||
if (name_copy == nullptr) {
|
||||
|
|
|
@ -56,7 +56,7 @@ uint32_t tox_event_conference_title_get_peer_number(const Tox_Event_Conference_T
|
|||
return conference_title->peer_number;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_conference_title_set_title(Tox_Event_Conference_Title *conference_title,
|
||||
const uint8_t *title, uint32_t title_length)
|
||||
{
|
||||
|
@ -68,6 +68,11 @@ static bool tox_event_conference_title_set_title(Tox_Event_Conference_Title *con
|
|||
conference_title->title_length = 0;
|
||||
}
|
||||
|
||||
if (title == nullptr) {
|
||||
assert(title_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *title_copy = (uint8_t *)malloc(title_length);
|
||||
|
||||
if (title_copy == nullptr) {
|
||||
|
|
|
@ -84,7 +84,7 @@ uint64_t tox_event_file_recv_get_file_size(const Tox_Event_File_Recv *file_recv)
|
|||
return file_recv->file_size;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_file_recv_set_filename(Tox_Event_File_Recv *file_recv,
|
||||
const uint8_t *filename, uint32_t filename_length)
|
||||
{
|
||||
|
@ -96,6 +96,11 @@ static bool tox_event_file_recv_set_filename(Tox_Event_File_Recv *file_recv,
|
|||
file_recv->filename_length = 0;
|
||||
}
|
||||
|
||||
if (filename == nullptr) {
|
||||
assert(filename_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *filename_copy = (uint8_t *)malloc(filename_length);
|
||||
|
||||
if (filename_copy == nullptr) {
|
||||
|
|
|
@ -70,7 +70,7 @@ uint64_t tox_event_file_recv_chunk_get_position(const Tox_Event_File_Recv_Chunk
|
|||
return file_recv_chunk->position;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_file_recv_chunk_set_data(Tox_Event_File_Recv_Chunk *file_recv_chunk,
|
||||
const uint8_t *data, uint32_t data_length)
|
||||
{
|
||||
|
@ -82,6 +82,11 @@ static bool tox_event_file_recv_chunk_set_data(Tox_Event_File_Recv_Chunk *file_r
|
|||
file_recv_chunk->data_length = 0;
|
||||
}
|
||||
|
||||
if (data == nullptr) {
|
||||
assert(data_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *data_copy = (uint8_t *)malloc(data_length);
|
||||
|
||||
if (data_copy == nullptr) {
|
||||
|
|
|
@ -42,7 +42,7 @@ uint32_t tox_event_friend_lossless_packet_get_friend_number(const Tox_Event_Frie
|
|||
return friend_lossless_packet->friend_number;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_friend_lossless_packet_set_data(Tox_Event_Friend_Lossless_Packet *friend_lossless_packet,
|
||||
const uint8_t *data, uint32_t data_length)
|
||||
{
|
||||
|
@ -54,6 +54,11 @@ static bool tox_event_friend_lossless_packet_set_data(Tox_Event_Friend_Lossless_
|
|||
friend_lossless_packet->data_length = 0;
|
||||
}
|
||||
|
||||
if (data == nullptr) {
|
||||
assert(data_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *data_copy = (uint8_t *)malloc(data_length);
|
||||
|
||||
if (data_copy == nullptr) {
|
||||
|
|
|
@ -42,7 +42,7 @@ uint32_t tox_event_friend_lossy_packet_get_friend_number(const Tox_Event_Friend_
|
|||
return friend_lossy_packet->friend_number;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_friend_lossy_packet_set_data(Tox_Event_Friend_Lossy_Packet *friend_lossy_packet,
|
||||
const uint8_t *data, uint32_t data_length)
|
||||
{
|
||||
|
@ -54,6 +54,11 @@ static bool tox_event_friend_lossy_packet_set_data(Tox_Event_Friend_Lossy_Packet
|
|||
friend_lossy_packet->data_length = 0;
|
||||
}
|
||||
|
||||
if (data == nullptr) {
|
||||
assert(data_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *data_copy = (uint8_t *)malloc(data_length);
|
||||
|
||||
if (data_copy == nullptr) {
|
||||
|
|
|
@ -58,7 +58,7 @@ Tox_Message_Type tox_event_friend_message_get_type(const Tox_Event_Friend_Messag
|
|||
return friend_message->type;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_friend_message_set_message(Tox_Event_Friend_Message *friend_message,
|
||||
const uint8_t *message, uint32_t message_length)
|
||||
{
|
||||
|
@ -70,6 +70,11 @@ static bool tox_event_friend_message_set_message(Tox_Event_Friend_Message *frien
|
|||
friend_message->message_length = 0;
|
||||
}
|
||||
|
||||
if (message == nullptr) {
|
||||
assert(message_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *message_copy = (uint8_t *)malloc(message_length);
|
||||
|
||||
if (message_copy == nullptr) {
|
||||
|
|
|
@ -42,7 +42,7 @@ uint32_t tox_event_friend_name_get_friend_number(const Tox_Event_Friend_Name *fr
|
|||
return friend_name->friend_number;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_friend_name_set_name(Tox_Event_Friend_Name *friend_name,
|
||||
const uint8_t *name, uint32_t name_length)
|
||||
{
|
||||
|
@ -54,6 +54,11 @@ static bool tox_event_friend_name_set_name(Tox_Event_Friend_Name *friend_name,
|
|||
friend_name->name_length = 0;
|
||||
}
|
||||
|
||||
if (name == nullptr) {
|
||||
assert(name_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *name_copy = (uint8_t *)malloc(name_length);
|
||||
|
||||
if (name_copy == nullptr) {
|
||||
|
|
|
@ -42,7 +42,7 @@ uint32_t tox_event_friend_status_message_get_friend_number(const Tox_Event_Frien
|
|||
return friend_status_message->friend_number;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_friend_status_message_set_message(Tox_Event_Friend_Status_Message *friend_status_message,
|
||||
const uint8_t *message, uint32_t message_length)
|
||||
{
|
||||
|
@ -54,6 +54,11 @@ static bool tox_event_friend_status_message_set_message(Tox_Event_Friend_Status_
|
|||
friend_status_message->message_length = 0;
|
||||
}
|
||||
|
||||
if (message == nullptr) {
|
||||
assert(message_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *message_copy = (uint8_t *)malloc(message_length);
|
||||
|
||||
if (message_copy == nullptr) {
|
||||
|
|
|
@ -56,7 +56,7 @@ uint32_t tox_event_group_custom_packet_get_peer_id(const Tox_Event_Group_Custom_
|
|||
return group_custom_packet->peer_id;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_custom_packet_set_data(Tox_Event_Group_Custom_Packet *group_custom_packet,
|
||||
const uint8_t *data, uint32_t data_length)
|
||||
{
|
||||
|
@ -68,6 +68,11 @@ static bool tox_event_group_custom_packet_set_data(Tox_Event_Group_Custom_Packet
|
|||
group_custom_packet->data_length = 0;
|
||||
}
|
||||
|
||||
if (data == nullptr) {
|
||||
assert(data_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *data_copy = (uint8_t *)malloc(data_length);
|
||||
|
||||
if (data_copy == nullptr) {
|
||||
|
|
|
@ -56,7 +56,7 @@ uint32_t tox_event_group_custom_private_packet_get_peer_id(const Tox_Event_Group
|
|||
return group_custom_private_packet->peer_id;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_custom_private_packet_set_data(Tox_Event_Group_Custom_Private_Packet *group_custom_private_packet,
|
||||
const uint8_t *data, uint32_t data_length)
|
||||
{
|
||||
|
@ -68,6 +68,11 @@ static bool tox_event_group_custom_private_packet_set_data(Tox_Event_Group_Custo
|
|||
group_custom_private_packet->data_length = 0;
|
||||
}
|
||||
|
||||
if (data == nullptr) {
|
||||
assert(data_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *data_copy = (uint8_t *)malloc(data_length);
|
||||
|
||||
if (data_copy == nullptr) {
|
||||
|
|
|
@ -44,7 +44,7 @@ uint32_t tox_event_group_invite_get_friend_number(const Tox_Event_Group_Invite *
|
|||
return group_invite->friend_number;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_invite_set_invite_data(Tox_Event_Group_Invite *group_invite,
|
||||
const uint8_t *invite_data, uint32_t invite_data_length)
|
||||
{
|
||||
|
@ -56,6 +56,11 @@ static bool tox_event_group_invite_set_invite_data(Tox_Event_Group_Invite *group
|
|||
group_invite->invite_data_length = 0;
|
||||
}
|
||||
|
||||
if (invite_data == nullptr) {
|
||||
assert(invite_data_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *invite_data_copy = (uint8_t *)malloc(invite_data_length);
|
||||
|
||||
if (invite_data_copy == nullptr) {
|
||||
|
@ -78,7 +83,7 @@ const uint8_t *tox_event_group_invite_get_invite_data(const Tox_Event_Group_Invi
|
|||
return group_invite->invite_data;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_invite_set_group_name(Tox_Event_Group_Invite *group_invite,
|
||||
const uint8_t *group_name, uint32_t group_name_length)
|
||||
{
|
||||
|
@ -90,6 +95,11 @@ static bool tox_event_group_invite_set_group_name(Tox_Event_Group_Invite *group_
|
|||
group_invite->group_name_length = 0;
|
||||
}
|
||||
|
||||
if (group_name == nullptr) {
|
||||
assert(group_name_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *group_name_copy = (uint8_t *)malloc(group_name_length);
|
||||
|
||||
if (group_name_copy == nullptr) {
|
||||
|
|
|
@ -73,7 +73,7 @@ Tox_Message_Type tox_event_group_message_get_type(const Tox_Event_Group_Message
|
|||
return group_message->type;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_message_set_message(Tox_Event_Group_Message *group_message,
|
||||
const uint8_t *message, uint32_t message_length)
|
||||
{
|
||||
|
@ -85,6 +85,11 @@ static bool tox_event_group_message_set_message(Tox_Event_Group_Message *group_m
|
|||
group_message->message_length = 0;
|
||||
}
|
||||
|
||||
if (message == nullptr) {
|
||||
assert(message_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *message_copy = (uint8_t *)malloc(message_length);
|
||||
|
||||
if (message_copy == nullptr) {
|
||||
|
|
|
@ -42,7 +42,7 @@ uint32_t tox_event_group_password_get_group_number(const Tox_Event_Group_Passwor
|
|||
return group_password->group_number;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_password_set_password(Tox_Event_Group_Password *group_password,
|
||||
const uint8_t *password, uint32_t password_length)
|
||||
{
|
||||
|
@ -54,6 +54,11 @@ static bool tox_event_group_password_set_password(Tox_Event_Group_Password *grou
|
|||
group_password->password_length = 0;
|
||||
}
|
||||
|
||||
if (password == nullptr) {
|
||||
assert(password_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *password_copy = (uint8_t *)malloc(password_length);
|
||||
|
||||
if (password_copy == nullptr) {
|
||||
|
|
|
@ -74,7 +74,7 @@ Tox_Group_Exit_Type tox_event_group_peer_exit_get_exit_type(const Tox_Event_Grou
|
|||
return group_peer_exit->exit_type;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_peer_exit_set_name(Tox_Event_Group_Peer_Exit *group_peer_exit,
|
||||
const uint8_t *name, uint32_t name_length)
|
||||
{
|
||||
|
@ -86,6 +86,11 @@ static bool tox_event_group_peer_exit_set_name(Tox_Event_Group_Peer_Exit *group_
|
|||
group_peer_exit->name_length = 0;
|
||||
}
|
||||
|
||||
if (name == nullptr) {
|
||||
assert(name_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *name_copy = (uint8_t *)malloc(name_length);
|
||||
|
||||
if (name_copy == nullptr) {
|
||||
|
@ -108,7 +113,7 @@ const uint8_t *tox_event_group_peer_exit_get_name(const Tox_Event_Group_Peer_Exi
|
|||
return group_peer_exit->name;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_peer_exit_set_part_message(Tox_Event_Group_Peer_Exit *group_peer_exit,
|
||||
const uint8_t *part_message, uint32_t part_message_length)
|
||||
{
|
||||
|
@ -120,6 +125,11 @@ static bool tox_event_group_peer_exit_set_part_message(Tox_Event_Group_Peer_Exit
|
|||
group_peer_exit->part_message_length = 0;
|
||||
}
|
||||
|
||||
if (part_message == nullptr) {
|
||||
assert(part_message_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *part_message_copy = (uint8_t *)malloc(part_message_length);
|
||||
|
||||
if (part_message_copy == nullptr) {
|
||||
|
|
|
@ -56,7 +56,7 @@ uint32_t tox_event_group_peer_name_get_peer_id(const Tox_Event_Group_Peer_Name *
|
|||
return group_peer_name->peer_id;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_peer_name_set_name(Tox_Event_Group_Peer_Name *group_peer_name,
|
||||
const uint8_t *name, uint32_t name_length)
|
||||
{
|
||||
|
@ -68,6 +68,11 @@ static bool tox_event_group_peer_name_set_name(Tox_Event_Group_Peer_Name *group_
|
|||
group_peer_name->name_length = 0;
|
||||
}
|
||||
|
||||
if (name == nullptr) {
|
||||
assert(name_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *name_copy = (uint8_t *)malloc(name_length);
|
||||
|
||||
if (name_copy == nullptr) {
|
||||
|
|
|
@ -72,7 +72,7 @@ Tox_Message_Type tox_event_group_private_message_get_type(const Tox_Event_Group_
|
|||
return group_private_message->type;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_private_message_set_message(Tox_Event_Group_Private_Message *group_private_message,
|
||||
const uint8_t *message, uint32_t message_length)
|
||||
{
|
||||
|
@ -84,6 +84,11 @@ static bool tox_event_group_private_message_set_message(Tox_Event_Group_Private_
|
|||
group_private_message->message_length = 0;
|
||||
}
|
||||
|
||||
if (message == nullptr) {
|
||||
assert(message_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *message_copy = (uint8_t *)malloc(message_length);
|
||||
|
||||
if (message_copy == nullptr) {
|
||||
|
|
|
@ -56,7 +56,7 @@ uint32_t tox_event_group_topic_get_peer_id(const Tox_Event_Group_Topic *group_to
|
|||
return group_topic->peer_id;
|
||||
}
|
||||
|
||||
non_null()
|
||||
non_null(1) nullable(2)
|
||||
static bool tox_event_group_topic_set_topic(Tox_Event_Group_Topic *group_topic,
|
||||
const uint8_t *topic, uint32_t topic_length)
|
||||
{
|
||||
|
@ -68,6 +68,11 @@ static bool tox_event_group_topic_set_topic(Tox_Event_Group_Topic *group_topic,
|
|||
group_topic->topic_length = 0;
|
||||
}
|
||||
|
||||
if (topic == nullptr) {
|
||||
assert(topic_length == 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t *topic_copy = (uint8_t *)malloc(topic_length);
|
||||
|
||||
if (topic_copy == nullptr) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user