From 75c3a395972e83366282eb049590338fd50b2fe2 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Mon, 25 May 2026 13:36:40 +0545 Subject: [PATCH] feat(src/daemon): add battery limit validation to set_battery_limit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The change ensures that only valid battery percentages (1‑100) are processed, preventing out‑of‑range values from reaching the underlying command. - New Features - Validation of battery limit percentage added. - Enhancements - Better error reporting for invalid arguments. - Bug Fixes - Prevents processing of invalid battery limit values. --- src/daemon/dbus_iface.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/daemon/dbus_iface.rs b/src/daemon/dbus_iface.rs index fc3679d..c2fa797 100644 --- a/src/daemon/dbus_iface.rs +++ b/src/daemon/dbus_iface.rs @@ -54,6 +54,12 @@ impl LapctlInterface { } pub async fn set_battery_limit(&self, percent: u32) -> zbus::fdo::Result<()> { + if percent == 0 || percent > 100 { + return Err(zbus::fdo::Error::InvalidArgs(format!( + "Invalid battery limit: {}. Must be between 1 and 100.", + percent + ))); + } crate::commands::battery::execute_local(&crate::cli::BatteryCommands::Limit { percent: percent as u8, });