public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Randy Dunlap <rdunlap@infradead.org>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: "Pavel Machek" <pavel@ucw.cz>,
	"Pali Rohár" <pali.rohar@gmail.com>,
	"Stefan Weil" <sw@weilnetz.de>, "Jiri Kosina" <jkosina@suse.cz>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Documentation: laptops: freefall.c:  Cleaning up missing null-terminate in conjunction with strncpy
Date: Sun, 27 Jul 2014 16:03:44 -0700	[thread overview]
Message-ID: <53D58550.6040205@infradead.org> (raw)
In-Reply-To: <1406472043-12272-1-git-send-email-rickard_strandqvist@spectrumdigital.se>

On 07/27/14 07:40, Rickard Strandqvist wrote:
> Added a guaranteed null-terminate after call to strncpy.
> 
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---
>  Documentation/laptops/freefall.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/laptops/freefall.c b/Documentation/laptops/freefall.c
> index aab2ff0..113d004 100644
> --- a/Documentation/laptops/freefall.c
> +++ b/Documentation/laptops/freefall.c
> @@ -33,8 +33,10 @@ static int set_unload_heads_path(char *device)
>  
>  	if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0)
>  		return -EINVAL;
> -	strncpy(devname, device + 5, sizeof(devname) - 1);
> -	strncpy(device_path, device, sizeof(device_path) - 1);

Maybe I am overlooking something here, but what was wrong with
the - 1 (2 times) above?  and then just add the 2 lines below that set the
last byte to '\0'?

> +	strncpy(devname, device + 5, sizeof(devname));
> +	devname[sizeof(devname) - 1] = '\0';
> +	strncpy(device_path, device, sizeof(device_path));
> +	device_path[sizeof(device_path) - 1] = '\0';
>  
>  	snprintf(unload_heads_path, sizeof(unload_heads_path) - 1,
>  				"/sys/block/%s/device/unload_heads", devname);
> 


-- 
~Randy

  parent reply	other threads:[~2014-07-27 23:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-27 14:40 [PATCH] Documentation: laptops: freefall.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
2014-07-27 19:29 ` Pavel Machek
2014-07-27 23:03 ` Randy Dunlap [this message]
2014-07-28 10:20   ` Pavel Machek
2014-07-28 11:10     ` [PATCHv2] Documentation: laptops: freefall.c: Fix missing null-termination Pavel Machek
2014-07-28 11:13     ` [PATCHv3] Documentation: laptops: freefall.c: simplify to avoid null-termination problems Pavel Machek
2014-07-29  0:17       ` Randy Dunlap

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=53D58550.6040205@infradead.org \
    --to=rdunlap@infradead.org \
    --cc=jkosina@suse.cz \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pali.rohar@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=rickard_strandqvist@spectrumdigital.se \
    --cc=sw@weilnetz.de \
    /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