Skip to content

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

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


I split this patch into two parts:

  • The first one with the above commit message, which fixes the crash and can be cherry-picked to Plasma/6.0.
  • The second one with just a commit title, which adds InlineMessage warnings to tell the user what's actually going on. Due to new strings, this should not go into Plasma/6.0.

Merge request reports

Loading