All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Alexander Viro <aviro@redhat.com>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] fs - fix name overwrite in __register_chrdev_region
Date: Mon, 15 Dec 2008 21:57:06 -0800	[thread overview]
Message-ID: <20081215215706.7707315c.akpm@linux-foundation.org> (raw)
In-Reply-To: <20081213214911.GI16354@localhost>

On Sun, 14 Dec 2008 00:49:11 +0300 Cyrill Gorcunov <gorcunov@gmail.com> wrote:

> It's possible to register chdev with a name size
> exactly the same as was allocated in structure.
> It seems it was not intedned behaviour.
> 
> At least chrdev_show does not like it.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> ---
> 
>  fs/char_dev.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Index: linux-2.6.git/fs/char_dev.c
> ===================================================================
> --- linux-2.6.git.orig/fs/char_dev.c
> +++ linux-2.6.git/fs/char_dev.c
> @@ -120,7 +120,7 @@ __register_chrdev_region(unsigned int ma
>  	cd->major = major;
>  	cd->baseminor = baseminor;
>  	cd->minorct = minorct;
> -	strncpy(cd->name,name, 64);
> +	strncpy(cd->name, name, sizeof(cd->name) - 1);
>  
>  	i = major_to_index(major);
>  

OK.

strlcpy() prodces a more pleasing result:

--- a/fs/char_dev.c~fs-fix-name-overwrite-in-__register_chrdev_region
+++ a/fs/char_dev.c
@@ -120,7 +120,7 @@ __register_chrdev_region(unsigned int ma
 	cd->major = major;
 	cd->baseminor = baseminor;
 	cd->minorct = minorct;
-	strncpy(cd->name,name, 64);
+	strlcpy(cd->name, name, sizeof(cd->name));
 
 	i = major_to_index(major);
 
_


  reply	other threads:[~2008-12-16  5:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-13 21:49 [PATCH] fs - fix name overwrite in __register_chrdev_region Cyrill Gorcunov
2008-12-16  5:57 ` Andrew Morton [this message]
2008-12-16  6:45   ` Cyrill Gorcunov

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=20081215215706.7707315c.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=aviro@redhat.com \
    --cc=gorcunov@gmail.com \
    --cc=linux-kernel@vger.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 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.