Skip to content

kcmodule: Don't crash when a configured button action is unsupported

Jakob Petsovits requested to merge work/cherry-pick-8ecf6430 into Plasma/6.0

The bounds check in the data() method of PowerButtonActionModel and SleepModeModel was incomplete, so passing an invalid index such as -1 (standard value for "not found") could cause a crash.

For power management settings, a user would run into this crash if their configuration from powerdevilrc listed a power button action that's not supported on the current system. For example, a user may have selected "Sleep" as lid action, but subsequently changed their systemd configuration to disable suspend-to-RAM because it caused problems. Or they could have migrated their OS to a new computer which does not support Sleep.

Fixing this allows us to assign currentIndex declaratively instead of waiting until Component.onCompleted to (hopefully) find a valid item in the model.

BUG: 482668

(cherry picked from commit 8ecf6430)

Merge request reports