Bug 465799 - segmentation fault if last used exporter disappears
Summary: segmentation fault if last used exporter disappears
Status: RESOLVED FIXED
Alias: None
Product: ghostwriter
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Arch Linux Linux
: VHI critical
Target Milestone: ---
Assignee: megan.conkle
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-15 23:20 UTC by Barnabás Pőcze
Modified: 2024-10-13 06:38 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Barnabás Pőcze 2023-02-15 23:20:25 UTC
The ghostwriter::AppSettings constructor will call `setOptions()` on an Exporter nullptr if `ExporterFactory::instance()->exporterByName(exporterName);` returns nullptr.


The following changes seems to fix it:

diff --git a/src/appsettings.cpp b/src/appsettings.cpp
index 5500108..38ca677 100644
--- a/src/appsettings.cpp
+++ b/src/appsettings.cpp
@@ -774,10 +774,11 @@ AppSettings::AppSettings()
 
     QString exporterName = appSettings.value(GW_LAST_USED_EXPORTER_KEY).toString();
     d->currentHtmlExporter = ExporterFactory::instance()->exporterByName(exporterName);
-    d->currentHtmlExporter->setOptions(appSettings.value(GW_LAST_USED_EXPORTER_PARAMS_KEY).toString());
 
     if (nullptr == d->currentHtmlExporter) {
         d->currentHtmlExporter = ExporterFactory::instance()->htmlExporters().first();
+    } else {
+        d->currentHtmlExporter->setOptions(appSettings.value(GW_LAST_USED_EXPORTER_PARAMS_KEY).toString());
     }
 }
Comment 1 megan.conkle 2024-10-13 06:38:14 UTC
Git commit f82070ac7916b36bb0bfd84a5c0e96cb084a6e28 by Megan Conkle.
Committed on 13/10/2024 at 06:34.
Pushed by wereturtle into branch 'master'.

Fix segmentation fault when .conf file is missing

Whenever ghostwriter.conf is missing (or the last used exporter within
is empty), the app will crash with a segmentation fault due to accessing
an uninitialed pointer to the current HTML exporter in appsettings.cpp.
This commit ensures that the pointer is initialized to null before being
checked for whether obtaining an exporter was successful.

M  +6    -0    CHANGELOG.md
M  +12   -12   src/preview/htmlpreview.cpp
M  +12   -6    src/settings/appsettings.cpp

https://invent.kde.org/office/ghostwriter/-/commit/f82070ac7916b36bb0bfd84a5c0e96cb084a6e28