* [PATCH] tools/leds: Build the full hardware brightness path
@ 2026-11-20 6:18 Zhu Jun
2026-11-20 6:21 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Zhu Jun @ 2026-11-20 6:18 UTC (permalink / raw)
To: lee; +Cc: pavel, griffin, jacek.anaszewski, linux-leds, linux-kernel,
Zhu Jun
The path includes both the LED class directory and the attribute
name, but snprintf() limits the entire result to the LED name size.
This truncates valid paths and causes open() to fail. Allow room
for the whole path and check for truncation before opening it.
Fixes: ae3473231e77 ("tools/leds: Add led_hw_brightness_mon program")
Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
tools/leds/led_hw_brightness_mon.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/tools/leds/led_hw_brightness_mon.c b/tools/leds/led_hw_brightness_mon.c
index eb65ae988839..c26be496a00d 100644
--- a/tools/leds/led_hw_brightness_mon.c
+++ b/tools/leds/led_hw_brightness_mon.c
@@ -14,6 +14,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
@@ -21,12 +22,10 @@
#include <time.h>
#include <unistd.h>
-#include <linux/uleds.h>
-
int main(int argc, char const *argv[])
{
int fd, ret;
- char brightness_file_path[LED_MAX_NAME_SIZE + 11];
+ char brightness_file_path[PATH_MAX];
struct pollfd pollfd;
struct timespec ts;
char buf[11];
@@ -36,8 +35,12 @@ int main(int argc, char const *argv[])
return 1;
}
- snprintf(brightness_file_path, LED_MAX_NAME_SIZE,
- "/sys/class/leds/%s/brightness_hw_changed", argv[1]);
+ ret = snprintf(brightness_file_path, sizeof(brightness_file_path),
+ "/sys/class/leds/%s/brightness_hw_changed", argv[1]);
+ if (ret < 0 || (size_t)ret >= sizeof(brightness_file_path)) {
+ fprintf(stderr, "Invalid LED brightness path\n");
+ return 1;
+ }
fd = open(brightness_file_path, O_RDONLY);
if (fd == -1) {
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] tools/leds: Build the full hardware brightness path
2026-11-20 6:18 [PATCH] tools/leds: Build the full hardware brightness path Zhu Jun
@ 2026-11-20 6:21 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-20 6:21 UTC (permalink / raw)
To: Zhu Jun; +Cc: linux-leds, lee
> The path includes both the LED class directory and the attribute
> name, but snprintf() limits the entire result to the LED name size.
> This truncates valid paths and causes open() to fail. Allow room
> for the whole path and check for truncation before opening it.
>
> Fixes: ae3473231e77 ("tools/leds: Add led_hw_brightness_mon program")
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120061840.98122-1-zhujun2@cmss.chinamobile.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 6:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 6:18 [PATCH] tools/leds: Build the full hardware brightness path Zhu Jun
2026-11-20 6:21 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox