All of lore.kernel.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Roel Kluin <12o3l@tiscali.nl>
Cc: linuxppc-dev@ozlabs.org, paulus@samba.org,
	lkml <linux-kernel@vger.kernel.org>,
	arnd@arndb.de
Subject: Re: [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy
Date: Thu, 6 Mar 2008 16:44:24 +0100	[thread overview]
Message-ID: <5adf51cc1df72cfd261e3c6e7bead312@kernel.crashing.org> (raw)
In-Reply-To: <47CFEE9D.1020300@tiscali.nl>

> This patch was not yet tested. Please confirm it's right.
> ---
> strncpy does not append '\0' if the length of the source string equals
> the size parameter, strlcpy does.

strlcpy() doesn't fill the rest of the array with zeroes, strncpy()
does.  This could matter (information leak, for example), although
I doubt it does here.

> -	strncpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
> +	strlcpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
>  	celleb_machine_type[sizeof(celleb_machine_type)-1] = 0;

That last statement makes the strncpy() case always zero-terminated,
so this patch isn't necessary.  Oh, and neither the old nor the new
code handles the case where the string doesn't fit (other than just
cutting it short); is that the wanted behaviour?


Segher

WARNING: multiple messages have this Message-ID (diff)
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Roel Kluin <12o3l@tiscali.nl>
Cc: paulus@samba.org, arnd@arndb.de, linuxppc-dev@ozlabs.org,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy
Date: Thu, 6 Mar 2008 16:44:24 +0100	[thread overview]
Message-ID: <5adf51cc1df72cfd261e3c6e7bead312@kernel.crashing.org> (raw)
In-Reply-To: <47CFEE9D.1020300@tiscali.nl>

> This patch was not yet tested. Please confirm it's right.
> ---
> strncpy does not append '\0' if the length of the source string equals
> the size parameter, strlcpy does.

strlcpy() doesn't fill the rest of the array with zeroes, strncpy()
does.  This could matter (information leak, for example), although
I doubt it does here.

> -	strncpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
> +	strlcpy(celleb_machine_type, ptr, sizeof(celleb_machine_type));
>  	celleb_machine_type[sizeof(celleb_machine_type)-1] = 0;

That last statement makes the strncpy() case always zero-terminated,
so this patch isn't necessary.  Oh, and neither the old nor the new
code handles the case where the string doesn't fit (other than just
cutting it short); is that the wanted behaviour?


Segher


  parent reply	other threads:[~2008-03-06 15:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-06 13:16 [PATCH] PPC: in celleb_show_cpuinfo() convert strncpy(x, y, sizeof(x)) to strlcpy Roel Kluin
2008-03-06 13:20 ` Roel Kluin
2008-03-07  8:06   ` Ishizaki Kou
2008-03-07  8:06     ` Ishizaki Kou
2008-03-06 15:44 ` Segher Boessenkool [this message]
2008-03-06 15:44   ` Segher Boessenkool

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=5adf51cc1df72cfd261e3c6e7bead312@kernel.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=12o3l@tiscali.nl \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=paulus@samba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.