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:
@@ -110,11 +110,11 @@ avatar_set(const char* path)
|
||||
{
|
||||
auto_char char* expanded_path = get_expanded_path(path);
|
||||
|
||||
GError* err = NULL;
|
||||
auto_gerror GError* err = NULL;
|
||||
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(expanded_path, &err);
|
||||
|
||||
if (pixbuf == NULL) {
|
||||
cons_show_error("An error occurred while opening %s: %s.", expanded_path, err ? err->message : "No error message given");
|
||||
cons_show_error("An error occurred while opening %s: %s.", expanded_path, PROF_GERROR_MESSAGE(err));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ avatar_set(const char* path)
|
||||
gsize len = -1;
|
||||
|
||||
if (!gdk_pixbuf_save_to_buffer(pixbuf, &img_data, &len, "png", &err, NULL)) {
|
||||
cons_show_error("Unable to scale and convert avatar.");
|
||||
cons_show_error("Unable to scale and convert avatar: %s.", PROF_GERROR_MESSAGE(err));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -342,11 +342,10 @@ _avatar_request_item_result_handler(xmpp_stanza_t* const stanza, void* const use
|
||||
g_string_append(filename, ".webp");
|
||||
}
|
||||
|
||||
GError* err = NULL;
|
||||
auto_gerror GError* err = NULL;
|
||||
if (g_file_set_contents(filename->str, de, size, &err) == FALSE) {
|
||||
log_error("Unable to save picture: %s", err->message);
|
||||
cons_show("Unable to save picture %s", err->message);
|
||||
g_error_free(err);
|
||||
} else {
|
||||
cons_show("Avatar saved as %s", filename->str);
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user