commit 7afc106f57f7583b01c796bd7259f8f9a589a2be
parent 6a980a285fcac517bd266e326e0da68680c2dce4
Author: Jacki <jacki@thejackimonster.de>
Date: Mon, 22 Apr 2024 00:22:41 +0200
Fix memory issues with file key changes
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
4 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c
@@ -50,7 +50,8 @@ file_create_from_message (struct GNUNET_CHAT_Handle *handle,
return NULL;
}
- GNUNET_memcpy(&(file->key), &(message->key), sizeof(message->key));
+ GNUNET_memcpy(file->key, &(message->key),
+ sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey));
GNUNET_memcpy(&(file->hash), &(message->hash), sizeof(file->hash));
file->meta = GNUNET_FS_meta_data_create();
@@ -148,7 +149,8 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle,
return NULL;
}
- GNUNET_memcpy(file->key, key, sizeof(*key));
+ GNUNET_memcpy(file->key, key,
+ sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey));
GNUNET_memcpy(&(file->hash), hash, sizeof(file->hash));
file->meta = GNUNET_FS_meta_data_create();
@@ -228,6 +230,9 @@ file_destroy (struct GNUNET_CHAT_File *file)
if (file->meta)
GNUNET_FS_meta_data_destroy(file->meta);
+ if (file->key)
+ GNUNET_free(file->key);
+
if (file->name)
GNUNET_free(file->name);
@@ -325,7 +330,8 @@ file_update_upload (struct GNUNET_CHAT_File *file,
msg.header.kind = GNUNET_MESSENGER_KIND_FILE;
if (file->key)
- GNUNET_memcpy(&(msg.body.file.key), file->key, sizeof(msg.body.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));
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h
@@ -76,8 +76,8 @@ struct GNUNET_CHAT_File
char *name;
struct GNUNET_HashCode hash;
- struct GNUNET_CRYPTO_SymmetricSessionKey *key;
+ struct GNUNET_CRYPTO_SymmetricSessionKey *key;
struct GNUNET_FS_MetaData *meta;
struct GNUNET_FS_Uri *uri;
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -1861,7 +1861,8 @@ GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context,
msg.header.kind = GNUNET_MESSENGER_KIND_FILE;
if (file->key)
- GNUNET_memcpy(&(msg.body.file.key), file->key, sizeof(msg.body.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));
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
@@ -1050,7 +1050,7 @@ cb_iterate_ticket_check (void *cls,
tick->ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
if (tick->ticket)
- GNUNET_memcpy (
+ GNUNET_memcpy(
tick->ticket,
ticket,
sizeof (struct GNUNET_RECLAIM_Ticket)