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:
@@ -70,10 +70,10 @@ cafile_add(const TLSCertificate* cert)
|
||||
auto_gchar gchar* contents = NULL;
|
||||
auto_gchar gchar* new_contents = NULL;
|
||||
gsize length;
|
||||
GError* glib_error = NULL;
|
||||
auto_gerror GError* glib_error = NULL;
|
||||
if (g_file_test(cafile, G_FILE_TEST_EXISTS)) {
|
||||
if (!g_file_get_contents(cafile, &contents, &length, &glib_error)) {
|
||||
log_error("[CAfile] could not read from %s: %s", cafile, glib_error ? glib_error->message : "No GLib error given");
|
||||
log_error("[CAfile] could not read from %s: %s", cafile, PROF_GERROR_MESSAGE(glib_error));
|
||||
return;
|
||||
}
|
||||
if (strstr(contents, cert->fingerprint)) {
|
||||
@@ -84,7 +84,7 @@ cafile_add(const TLSCertificate* cert)
|
||||
const char* header = "# Profanity CAfile\n# DO NOT EDIT - this file is automatically generated";
|
||||
new_contents = g_strdup_printf("%s\n\n# %s\n%s", contents ? contents : header, cert->fingerprint, cert->pem);
|
||||
if (!g_file_set_contents(cafile, new_contents, -1, &glib_error))
|
||||
log_error("[CAfile] could not write to %s: %s", cafile, glib_error ? glib_error->message : "No GLib error given");
|
||||
log_error("[CAfile] could not write to %s: %s", cafile, PROF_GERROR_MESSAGE(glib_error));
|
||||
}
|
||||
|
||||
gchar*
|
||||
|
||||
@@ -89,7 +89,7 @@ _prefs_load(void)
|
||||
log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err);
|
||||
if (err) {
|
||||
log_maxsize = 0;
|
||||
g_error_free(err);
|
||||
PROF_GERROR_FREE(err);
|
||||
}
|
||||
|
||||
// move pre 0.5.0 autoaway.time to autoaway.awaytime
|
||||
|
||||
Reference in New Issue
Block a user