diff options
| author | drkhsh <me@drkhsh.at> | 2026-02-12 22:52:21 +0100 |
|---|---|---|
| committer | drkhsh <me@drkhsh.at> | 2026-02-12 22:52:21 +0100 |
| commit | 98769dfed7266b5a9959162e03bee1ddfaf5ecb4 (patch) | |
| tree | 5ef79b4995a89cff511eec651842639a653df9d7 | |
| parent | 4f61bbbd8e9278c75f29e7853ae8922717261d2d (diff) | |
| download | slstatus-98769dfed7266b5a9959162e03bee1ddfaf5ecb4.tar.gz | |
fix buffer overflow in battery state parsing
"Not charging" is 12 characters; %12[a-zA-Z ] reads up to 12 chars
plus a NUL terminator (13 bytes) into a 12-byte buffer. Increase
state buffer to 13 in both battery_state and battery_remaining.
| -rw-r--r-- | components/battery.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/components/battery.c b/components/battery.c index 1c753f9..f2dc393 100644 --- a/components/battery.c +++ b/components/battery.c @@ -62,7 +62,7 @@ { "Not charging", "o" }, }; size_t i; - char path[PATH_MAX], state[12]; + char path[PATH_MAX], state[13]; if (esnprintf(path, sizeof(path), POWER_SUPPLY_STATUS, bat) < 0) return NULL; @@ -81,7 +81,7 @@ { uintmax_t charge_now, current_now, m, h; double timeleft; - char path[PATH_MAX], state[12]; + char path[PATH_MAX], state[13]; if (esnprintf(path, sizeof(path), POWER_SUPPLY_STATUS, bat) < 0) return NULL; |
