mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-22 00:06:21 +00:00
Fix GError handling
Several users have reported segfaults when starting up profanity which has OMEMO support, but OMEMO is not set up yet. @StefanKropp has been able to reproduce this and tracked it down to `_load_identity()` calling `omemo_known_devices_keyfile_save()`. The latter then calls `save_keyfile()` which calls `g_key_file_save_to_file()`. This can then fail if one of the first two strings is NULL and won't set the `error` on return. In its error handling `save_keyfile()` unconditionally dereferences `error` which leads to the segfault. Fix this and also go through the entire codebase and verify that the usage of `GError` is done correctly. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -1426,11 +1426,10 @@ omemo_automatic_start(const char* const recipient)
|
||||
static gboolean
|
||||
_load_identity(void)
|
||||
{
|
||||
GError* error = NULL;
|
||||
auto_gerror GError* error = NULL;
|
||||
log_info("[OMEMO] Loading OMEMO identity");
|
||||
|
||||
/* Device ID */
|
||||
error = NULL;
|
||||
omemo_ctx.device_id = g_key_file_get_uint64(omemo_ctx.identity.keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_DEVICE_ID, &error);
|
||||
if (error != NULL) {
|
||||
log_error("[OMEMO] cannot load device id: %s", error->message);
|
||||
@@ -1439,7 +1438,6 @@ _load_identity(void)
|
||||
log_debug("[OMEMO] device id: %d", omemo_ctx.device_id);
|
||||
|
||||
/* Registration ID */
|
||||
error = NULL;
|
||||
omemo_ctx.registration_id = g_key_file_get_uint64(omemo_ctx.identity.keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_REGISTRATION_ID, &error);
|
||||
if (error != NULL) {
|
||||
log_error("[OMEMO] cannot load registration id: %s", error->message);
|
||||
@@ -1447,10 +1445,9 @@ _load_identity(void)
|
||||
}
|
||||
|
||||
/* Identity key */
|
||||
error = NULL;
|
||||
auto_gchar gchar* identity_key_public_b64 = g_key_file_get_string(omemo_ctx.identity.keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_IDENTITY_KEY_PUBLIC, &error);
|
||||
if (!identity_key_public_b64) {
|
||||
log_error("[OMEMO] cannot load identity public key: %s", error->message);
|
||||
log_error("[OMEMO] cannot load identity public key: %s", PROF_GERROR_MESSAGE(error));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -1458,10 +1455,9 @@ _load_identity(void)
|
||||
auto_guchar guchar* identity_key_public = g_base64_decode(identity_key_public_b64, &identity_key_public_len);
|
||||
omemo_ctx.identity_key_store.public = signal_buffer_create(identity_key_public, identity_key_public_len);
|
||||
|
||||
error = NULL;
|
||||
auto_gchar gchar* identity_key_private_b64 = g_key_file_get_string(omemo_ctx.identity.keyfile, OMEMO_STORE_GROUP_IDENTITY, OMEMO_STORE_KEY_IDENTITY_KEY_PRIVATE, &error);
|
||||
if (!identity_key_private_b64) {
|
||||
log_error("[OMEMO] cannot load identity private key: %s", error->message);
|
||||
log_error("[OMEMO] cannot load identity private key: %s", PROF_GERROR_MESSAGE(error));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user