mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: Gu Bin <gubin@cmss.chinamobile.com>, lee@kernel.org
Cc: pavel@kernel.org, linux-leds@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/leds/uledmon: force NUL-termination of device name
Date: Fri, 6 Nov 2026 08:05:00 -0600	[thread overview]
Message-ID: <1e1323a9-0567-48f6-84ed-3f3311196dbd@lechnology.com> (raw)
In-Reply-To: <20261106100614.2312-1-gubin@cmss.chinamobile.com>

On 11/6/26 4:06 AM, Gu Bin wrote:
> strncpy() does not NUL-terminate when the source is at least as long
> as the bound. uleds_dev.name is passed to the kernel with
> write(fd, &uleds_dev, sizeof(uleds_dev)), so a >= LED_MAX_NAME_SIZE
> byte argv[1] leaves name without a terminator and the write sends
> trailing bytes that are not part of a valid device name.
> 
> Force NUL-termination after the strncpy.
> 
> Fixes: fa7f32422ea1 ("tools/leds: Add uledmon program for monitoring userspace LEDs")
> Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
> ---
>  tools/leds/uledmon.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/leds/uledmon.c b/tools/leds/uledmon.c
> index c15a39c1f271..6df35b817233 100644
> --- a/tools/leds/uledmon.c
> +++ b/tools/leds/uledmon.c
> @@ -32,6 +32,7 @@ int main(int argc, char const *argv[])
>  	}
>  
>  	strncpy(uleds_dev.name, argv[1], LED_MAX_NAME_SIZE);
> +	uleds_dev.name[LED_MAX_NAME_SIZE - 1] = '\0';
>  	uleds_dev.max_brightness = 100;
>  
>  	fd = open("/dev/uleds", O_RDWR);

This works, but maybe better to just print an error and exit with error code
rather than silently truncating the name?

      reply	other threads:[~2026-11-06 14:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 10:06 Gu Bin
2026-11-06 14:05 ` David Lechner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1e1323a9-0567-48f6-84ed-3f3311196dbd@lechnology.com \
    --to=david@lechnology.com \
    --cc=gubin@cmss.chinamobile.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®