mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Jules Maselbas <jmaselbas@zdiv.net>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] commands: hwclock: replace strncpy with strlcpy
Date: Mon, 17 Mar 2025 09:42:19 +0100	[thread overview]
Message-ID: <Z9fga36NGkFsrZ82@pengutronix.de> (raw)
In-Reply-To: <20250314213344.12335-1-jmaselbas@zdiv.net>

Hi Jules,

On Fri, Mar 14, 2025 at 10:33:44PM +0100, Jules Maselbas wrote:
> strncpy could leave the rtc_name buffer not nul-terminated, strlcpy will
> always nul-terminate the dst buffer.
> Also replace the hardcoded size with sizeof(rtc_name)
> 
> Signed-off-by: Jules Maselbas <jmaselbas@zdiv.net>
> ---
>  commands/hwclock.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/commands/hwclock.c b/commands/hwclock.c
> index c594e070ac..33829e4118 100644
> --- a/commands/hwclock.c
> +++ b/commands/hwclock.c
> @@ -95,7 +95,7 @@ static int do_hwclock(int argc, char *argv[])
>  
>  		switch (opt) {
>  		case 'f':
> -			strncpy(rtc_name, optarg, 16);
> +			strlcpy(rtc_name, optarg, sizeof(rtc_name));
>  			break;

rtc_name is an array for no good reason. Can we just do a

const char *rtc_name = "rtc0";

		case 'f':
			rtc_name = optarg;

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      reply	other threads:[~2025-03-17  8:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-14 21:33 Jules Maselbas
2025-03-17  8:42 ` Sascha Hauer [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=Z9fga36NGkFsrZ82@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=jmaselbas@zdiv.net \
    /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