Fix segfault in gnc_gsettings_get_settings_obj when GSettings schemas are not installed

Add NULL guards before dereferencing return values from GLib calls to prevent
segmentation faults when GSettings schemas are missing (e.g., in library-only builds).

The crash occurred when g_settings_schema_source_get_default() returned NULL
and was passed directly to g_settings_schema_source_lookup(), causing a NULL
pointer dereference. The existing G_IS_SETTINGS check came too late.

Changes:
- Add NULL check for schema_source before using it
- Add NULL check for schema before calling g_settings_new_full()
- Add NULL guard in gnc_settings_dump_schema_paths() for consistency
- All callers already handle NULL returns via G_IS_SETTINGS checks

Fixes: https://bugs.gnucash.org/show_bug.cgi?id=799740

https://claude.ai/code/session_01Cdnp3XkAQ29hG1eCxUSAUw
pull/2179/head
Claude 3 months ago
parent 3cee6a3bbc
commit 606fc45582
No known key found for this signature in database

@ -105,7 +105,21 @@ static GSettings * gnc_gsettings_get_settings_obj (const gchar *schema_str)
auto full_name_str = normalize_schema_name (schema_str);
auto full_name = full_name_str.c_str();
auto schema_source {g_settings_schema_source_get_default()};
if (!schema_source)
{
PWARN ("No GSettings schema source available; cannot access schema %s", full_name);
LEAVE("");
return nullptr;
}
auto schema {g_settings_schema_source_lookup(schema_source, full_name, true)};
if (!schema)
{
PWARN ("GSettings schema %s not found", full_name);
LEAVE("");
return nullptr;
}
auto gset = g_settings_new_full (schema, nullptr, nullptr);
DEBUG ("Created gsettings object %p for schema %s", gset, full_name);
@ -545,6 +559,12 @@ gnc_settings_dump_schema_paths (void)
gchar **non_relocatable;
auto schema_source {g_settings_schema_source_get_default()};
if (!schema_source)
{
PWARN ("No GSettings schema source available; cannot dump schema paths");
return;
}
g_settings_schema_source_list_schemas (schema_source, true,
&non_relocatable, nullptr);

Loading…
Cancel
Save