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:
Steffen Jaeckel
2025-10-09 10:23:00 +02:00
parent 5da079bbb2
commit 48ac88de08
15 changed files with 57 additions and 66 deletions

View File

@@ -1338,11 +1338,10 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
g_string_append(filename, ".webp");
}
GError* err = NULL;
auto_gerror GError* err = NULL;
if (g_file_set_contents(filename->str, (gchar*)photo->data, photo->length, &err) == FALSE) {
cons_show_error("Unable to save photo: %s", err->message);
g_error_free(err);
cons_show_error("Unable to save photo: %s", PROF_GERROR_MESSAGE(err));
g_string_free(filename, TRUE);
return 1;
} else {
@@ -1360,7 +1359,7 @@ _vcard_photo_result(xmpp_stanza_t* const stanza, void* userdata)
g_string_append(filename, "\"");
auto_char char* cmd = str_replace(cmdtemplate, "%p", filename->str);
if (g_shell_parse_argv(cmd, &argc, &argv, &err) == FALSE) {
if (g_shell_parse_argv(cmd, &argc, &argv, NULL) == FALSE) {
cons_show_error("Failed to parse command template");
} else {
if (!call_external(argv)) {