Bug 798531 - Selecting "Print" from the file menu on a report...

crashes gnucash

Ensure that every call to gnc_prefs_get_string correctly handles both
a NULL or empty string return value without crashing or leaking.
This commit is contained in:
John Ralls
2022-05-20 14:33:29 -07:00
parent 10facd40c3
commit 564d73a553
5 changed files with 28 additions and 17 deletions

View File

@@ -210,13 +210,15 @@ gnc_get_default_directory (const gchar *section)
gchar *dir;
dir = gnc_prefs_get_string (section, GNC_PREF_LAST_PATH);
if (!dir)
if (!(dir && *dir))
{
g_free (dir); // if it's ""
#ifdef G_OS_WIN32
dir = g_strdup (g_get_user_data_dir ()); /* equivalent of "My Documents" */
#else
dir = g_strdup (g_get_home_dir ());
#endif
}
return dir;
}
@@ -1176,7 +1178,8 @@ gnc_default_currency_common (gchar *requested_currency,
mnemonic = gnc_prefs_get_string(section, GNC_PREF_CURRENCY_OTHER);
currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
GNC_COMMODITY_NS_CURRENCY, mnemonic);
DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
DEBUG("mnemonic %s, result %p",
mnemonic && *mnemonic ? mnemonic : "(null)", currency);
g_free(mnemonic);
}