aboutsummaryrefslogtreecommitdiff
path: root/plugins/signal-protocol/src/signal_helper.c
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-04-18 17:55:20 +0200
committerMarvin W <git@larma.de>2017-04-18 20:20:41 +0200
commit7e388fb2bc784568734592dcb2e863dfa061bed4 (patch)
treeeb4fb804fd7cf9df02b39d37b61937f355785810 /plugins/signal-protocol/src/signal_helper.c
parentf95b4f4e0949eefaed871c267626e3ff84ce5ca6 (diff)
downloaddino-7e388fb2bc784568734592dcb2e863dfa061bed4.tar.gz
dino-7e388fb2bc784568734592dcb2e863dfa061bed4.zip
signal-protocol/omemo: fix null-pointer issues
Fixes #44 and #58
Diffstat (limited to 'plugins/signal-protocol/src/signal_helper.c')
-rw-r--r--plugins/signal-protocol/src/signal_helper.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/plugins/signal-protocol/src/signal_helper.c b/plugins/signal-protocol/src/signal_helper.c
index d13b9c95..5cbf2ce2 100644
--- a/plugins/signal-protocol/src/signal_helper.c
+++ b/plugins/signal-protocol/src/signal_helper.c
@@ -3,14 +3,30 @@
#include <gcrypt.h>
-signal_protocol_address* signal_protocol_address_new() {
+signal_type_base* signal_type_ref_vapi(signal_type_base* instance) {
+ g_return_val_if_fail(instance != NULL, NULL);
+ signal_type_ref(instance);
+ return instance;
+}
+
+signal_type_base* signal_type_unref_vapi(signal_type_base* instance) {
+ g_return_val_if_fail(instance != NULL, NULL);
+ signal_type_unref(instance);
+ return NULL;
+}
+
+signal_protocol_address* signal_protocol_address_new(const gchar* name, int32_t device_id) {
+ g_return_val_if_fail(name != NULL, NULL);
signal_protocol_address* address = malloc(sizeof(signal_protocol_address));
- address->name = 0;
- address->device_id = 0;
+ address->device_id = NULL;
+ address->name = NULL;
+ signal_protocol_address_set_name(address, name);
+ signal_protocol_address_set_device_id(address, device_id);
return address;
}
void signal_protocol_address_free(signal_protocol_address* ptr) {
+ g_return_if_fail(ptr != NULL);
if (ptr->name) {
g_free((void*)ptr->name);
}
@@ -18,6 +34,8 @@ void signal_protocol_address_free(signal_protocol_address* ptr) {
}
void signal_protocol_address_set_name(signal_protocol_address* self, const gchar* name) {
+ g_return_if_fail(self != NULL);
+ g_return_if_fail(name != NULL);
gchar* n = g_malloc(strlen(name)+1);
memcpy(n, name, strlen(name));
n[strlen(name)] = 0;
@@ -29,13 +47,25 @@ void signal_protocol_address_set_name(signal_protocol_address* self, const gchar
}
gchar* signal_protocol_address_get_name(signal_protocol_address* self) {
- if (self->name == 0) return 0;
+ g_return_val_if_fail(self != NULL, NULL);
+ g_return_val_if_fail(self->name != NULL, 0);
gchar* res = g_malloc(sizeof(char) * (self->name_len + 1));
memcpy(res, self->name, self->name_len);
res[self->name_len] = 0;
return res;
}
+int32_t signal_protocol_address_get_device_id(signal_protocol_address* self) {
+ g_return_val_if_fail(self != NULL, NULL);
+ return self->device_id;
+}
+
+void signal_protocol_address_set_device_id(signal_protocol_address* self, int32_t device_id) {
+ g_return_if_fail(self != NULL);
+ self->device_id = device_id;
+}
+
+
session_pre_key* session_pre_key_new(uint32_t pre_key_id, ec_key_pair* pair, int* err) {
session_pre_key* res;
*err = session_pre_key_create(&res, pre_key_id, pair);