commit e2193576bb83a8cbcb1e752784b1121001864d94
parent fa31fdeddfacd772c8a87fa3e378214d734aa441
Author: Jacki <jacki@thejackimonster.de>
Date: Sat, 11 May 2024 23:29:34 +0200
Initialize messages before sending with zeroes
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
6 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
@@ -367,6 +367,8 @@ skip_tag_search:
char *tag_value = tag? GNUNET_strdup(tag) : NULL;
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
+
msg.header.kind = GNUNET_MESSENGER_KIND_TAG;
GNUNET_memcpy(&(msg.body.tag.hash), hash,
sizeof(struct GNUNET_HashCode));
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c
@@ -346,13 +346,13 @@ file_update_upload (struct GNUNET_CHAT_File *file,
return;
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
+
msg.header.kind = GNUNET_MESSENGER_KIND_FILE;
if (file->key)
GNUNET_memcpy(&(msg.body.file.key), file->key,
sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey));
- else
- memset(&(msg.body.file.key), 0, sizeof(msg.body.file.key));
GNUNET_memcpy(&(msg.body.file.hash), &(file->hash), sizeof(file->hash));
GNUNET_strlcpy(msg.body.file.name, file->name, NAME_MAX);
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
@@ -837,6 +837,7 @@ handle_send_room_name (struct GNUNET_CHAT_Handle *handle,
return;
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
msg.header.kind = GNUNET_MESSENGER_KIND_NAME;
msg.body.name.name = GNUNET_strdup(name);
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -1422,6 +1422,8 @@ GNUNET_CHAT_group_invite_contact (const struct GNUNET_CHAT_Group *group,
));
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
+
msg.header.kind = GNUNET_MESSENGER_KIND_INVITE;
GNUNET_CRYPTO_get_peer_identity(group->handle->cfg, &(msg.body.invite.door));
GNUNET_memcpy(&(msg.body.invite.key), key, sizeof(msg.body.invite.key));
@@ -1574,6 +1576,8 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context)
handle_send_room_name(handle, room);
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
+
msg.header.kind = GNUNET_MESSENGER_KIND_INVITE;
GNUNET_CRYPTO_get_peer_identity(handle->cfg, &(msg.body.invite.door));
GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key));
@@ -1669,6 +1673,8 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context,
return GNUNET_SYSERR;
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
+
msg.header.kind = GNUNET_MESSENGER_KIND_TEXT;
msg.body.text.text = GNUNET_strdup(text);
@@ -1690,6 +1696,8 @@ GNUNET_CHAT_context_send_read_receipt (struct GNUNET_CHAT_Context *context,
char zero = '\0';
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
+
msg.header.kind = GNUNET_MESSENGER_KIND_TEXT;
msg.body.text.text = &zero;
@@ -1839,6 +1847,8 @@ GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context,
return GNUNET_SYSERR;
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
+
msg.header.kind = GNUNET_MESSENGER_KIND_FILE;
if (file->key)
@@ -1871,6 +1881,8 @@ GNUNET_CHAT_context_send_tag (struct GNUNET_CHAT_Context *context,
char *tag_value = GNUNET_strdup(tag);
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
+
msg.header.kind = GNUNET_MESSENGER_KIND_TAG;
GNUNET_memcpy(&(msg.body.tag.hash), &(message->hash),
sizeof(struct GNUNET_HashCode));
@@ -2696,6 +2708,7 @@ GNUNET_CHAT_invitation_reject (struct GNUNET_CHAT_Invitation *invitation)
return;
struct GNUNET_MESSENGER_Message msg;
+ memset(&msg, 0, sizeof(msg));
msg.header.kind = GNUNET_MESSENGER_KIND_TAG;
GNUNET_memcpy(&(msg.body.tag.hash), &(invitation->hash),
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
@@ -718,6 +718,8 @@ cb_issue_ticket (void *cls,
goto skip_sending;
struct GNUNET_MESSENGER_Message message;
+ memset(&message, 0, sizeof(message));
+
message.header.kind = GNUNET_MESSENGER_KIND_TICKET;
message.body.ticket.identifier = identifier;
diff --git a/tests/test_gnunet_chat_attribute.c b/tests/test_gnunet_chat_attribute.c
@@ -170,9 +170,12 @@ on_gnunet_chat_attribute_share_attr(void *cls,
const struct GNUNET_CHAT_Account *account;
account = GNUNET_CHAT_get_connected(handle);
+ const char *account_name = GNUNET_CHAT_account_get_name(account);
+ const char *contact_name = GNUNET_CHAT_contact_get_name(contact);
+
ck_assert_ptr_nonnull(account);
- ck_assert_str_eq(GNUNET_CHAT_account_get_name(account), TEST_SHARE_ID_B);
- ck_assert_str_eq(GNUNET_CHAT_contact_get_name(contact), TEST_SHARE_ID_A);
+ ck_assert_str_eq(account_name, TEST_SHARE_ID_B);
+ ck_assert_str_eq(contact_name, TEST_SHARE_ID_A);
ck_assert_str_eq(name, TEST_SHARE_NAME);
ck_assert_str_eq(value, TEST_SHARE_VALUE);
@@ -190,6 +193,7 @@ on_gnunet_chat_attribute_share_msg(void *cls,
);
const struct GNUNET_CHAT_Account *account;
+ struct GNUNET_CHAT_Contact *recipient;
struct GNUNET_CHAT_Contact *sender;
const char *name;
@@ -197,6 +201,7 @@ on_gnunet_chat_attribute_share_msg(void *cls,
ck_assert_ptr_nonnull(message);
account = GNUNET_CHAT_message_get_account(message);
+ recipient = GNUNET_CHAT_message_get_recipient(message);
sender = GNUNET_CHAT_message_get_sender(message);
switch (GNUNET_CHAT_message_get_kind(message))
@@ -285,7 +290,6 @@ on_gnunet_chat_attribute_share_msg(void *cls,
), GNUNET_OK);
else if (GNUNET_YES != GNUNET_CHAT_message_is_sent(message))
GNUNET_CHAT_share_attribute_with(handle, sender, TEST_SHARE_NAME);
-
break;
case GNUNET_CHAT_KIND_CONTACT:
ck_assert_ptr_nonnull(context);
@@ -295,19 +299,24 @@ on_gnunet_chat_attribute_share_msg(void *cls,
ck_assert_ptr_null(context);
break;
case GNUNET_CHAT_KIND_SHARED_ATTRIBUTES:
- if (GNUNET_YES != GNUNET_CHAT_message_is_sent(message))
+ if (!context)
{
- printf("exit?\n");
+ ck_assert_ptr_null(account);
+ ck_assert_ptr_null(sender);
+ ck_assert_ptr_null(recipient);
GNUNET_CHAT_disconnect(handle);
}
- else
+ else if (GNUNET_YES == GNUNET_CHAT_message_is_sent(message))
{
- printf("list attributes?\n");
-
+ ck_assert_ptr_nonnull(account);
+ ck_assert_ptr_nonnull(sender);
+ ck_assert_ptr_nonnull(recipient);
+ ck_assert_ptr_ne(sender, recipient);
+
GNUNET_CHAT_get_shared_attributes(
handle,
- GNUNET_CHAT_message_get_recipient(message),
+ recipient,
on_gnunet_chat_attribute_share_attr,
handle
);