Bug 457285

Summary: KConfigWatcher::config() returns nullptr when built without DBUS support
Product: [Frameworks and Libraries] frameworks-kconfig Reporter: Kamil Dudka <kdudka>
Component: generalAssignee: Matthew Dawson <matthew>
Status: ASSIGNED ---    
Severity: normal CC: kdelibs-bugs
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: [PATCH] KConfigWatcher: initialize d->m_config in constructor

Description Kamil Dudka 2022-07-29 22:19:43 UTC
As additional KDE applications started to use KConfigWatcher, they started to crash on my laptop running Gentoo Linux.  I was trying to patch them one by one to prevent the crashes.  Then I realized that kconfig was built without dbus support on my system.  After rebuilding kconfig with -DKCONFIG_USE_DBUS, the crashes went away.

I looked into the source code of KConfigWatcher and discovered that its constructor initializes d->m_config only if KCONFIG_USE_DBUS is defined: https://github.com/KDE/kconfig/blob/491f5464/src/core/kconfigwatcher.cpp#L47

Consequently KConfigWatcher::config() may return nullptr, which triggers null dereference at caller's side, where a non-null value is expected.

STEPS TO REPRODUCE
1. build kconfig without dbus support

OBSERVED RESULT
Applications like plasma or kwin start to crash.

EXPECTED RESULT
No crashes.

SOFTWARE/OS VERSIONS
Linux: 5.15.52-gentoo-x86_64
KDE Plasma Version: 5.24.5
KDE Frameworks Version: 5.92.0
Qt Version: 5.15.5

ADDITIONAL INFORMATION
Previously reported with backtraces at:
bug #423864 comment #4
bug #453242
Comment 1 Kamil Dudka 2022-07-29 22:30:16 UTC
Created attachment 150988 [details]
[PATCH] KConfigWatcher: initialize d->m_config in constructor
Comment 2 Kamil Dudka 2022-08-05 08:16:21 UTC
I have submitted a merge request to fix this: https://invent.kde.org/frameworks/kconfig/-/merge_requests/134