* [PATCH] fs - fix name overwrite in __register_chrdev_region
@ 2008-12-13 21:49 Cyrill Gorcunov
2008-12-16 5:57 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Cyrill Gorcunov @ 2008-12-13 21:49 UTC (permalink / raw)
To: Andrew Morton, Alexander Viro; +Cc: LKML
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);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fs - fix name overwrite in __register_chrdev_region
2008-12-13 21:49 [PATCH] fs - fix name overwrite in __register_chrdev_region Cyrill Gorcunov
@ 2008-12-16 5:57 ` Andrew Morton
2008-12-16 6:45 ` Cyrill Gorcunov
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-12-16 5:57 UTC (permalink / raw)
To: Cyrill Gorcunov; +Cc: Alexander Viro, LKML
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);
_
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fs - fix name overwrite in __register_chrdev_region
2008-12-16 5:57 ` Andrew Morton
@ 2008-12-16 6:45 ` Cyrill Gorcunov
0 siblings, 0 replies; 3+ messages in thread
From: Cyrill Gorcunov @ 2008-12-16 6:45 UTC (permalink / raw)
To: Andrew Morton; +Cc: Alexander Viro, LKML
On Tue, Dec 16, 2008 at 8:57 AM, Andrew Morton
<akpm@linux-foundation.org> wrote:
>
> 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);
>
> _
>
Thanks, Andrew!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-12-16 6:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-13 21:49 [PATCH] fs - fix name overwrite in __register_chrdev_region Cyrill Gorcunov
2008-12-16 5:57 ` Andrew Morton
2008-12-16 6:45 ` Cyrill Gorcunov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox