qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] correctly null terminate the process name
@ 2011-10-18  2:06 Trevor Saunders
  2011-10-18  4:19 ` Stefan Weil
  0 siblings, 1 reply; 3+ messages in thread
From: Trevor Saunders @ 2011-10-18  2:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Trevor Saunders

strncpy() doesn't garentee the copied string will be null terminated if
the original is longer than the length to copy.

Signed-off-by: Trevor Saunders <trev.saunders@gmail.com>
---
 os-posix.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index dbf3b24..92dcc97 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -149,8 +149,8 @@ void os_set_proc_name(const char *s)
     char name[16];
     if (!s)
         return;
-    name[sizeof(name) - 1] = 0;
     strncpy(name, s, sizeof(name));
+    name[sizeof(name) - 1] = 0;
     /* Could rewrite argv[0] too, but that's a bit more complicated.
        This simple way is enough for `top'. */
     if (prctl(PR_SET_NAME, name)) {
-- 
1.7.7

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] correctly null terminate the process name
  2011-10-18  2:06 [Qemu-devel] [PATCH] correctly null terminate the process name Trevor Saunders
@ 2011-10-18  4:19 ` Stefan Weil
  2011-10-18  5:06   ` malc
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Weil @ 2011-10-18  4:19 UTC (permalink / raw)
  To: Trevor Saunders; +Cc: qemu-trivial, Jes Sorensen, qemu-devel

Am 18.10.2011 04:06, schrieb Trevor Saunders:
> strncpy() doesn't garentee the copied string will be null terminated if
> the original is longer than the length to copy.
>
> Signed-off-by: Trevor Saunders<trev.saunders@gmail.com>
> ---
>   os-posix.c |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/os-posix.c b/os-posix.c
> index dbf3b24..92dcc97 100644
> --- a/os-posix.c
> +++ b/os-posix.c
> @@ -149,8 +149,8 @@ void os_set_proc_name(const char *s)
>       char name[16];
>       if (!s)
>           return;
> -    name[sizeof(name) - 1] = 0;
>       strncpy(name, s, sizeof(name));
> +    name[sizeof(name) - 1] = 0;
>       /* Could rewrite argv[0] too, but that's a bit more complicated.
>          This simple way is enough for `top'. */
>       if (prctl(PR_SET_NAME, name)) {

Reviewed-by: Stefan Weil <sw@weilnetz.de>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] correctly null terminate the process name
  2011-10-18  4:19 ` Stefan Weil
@ 2011-10-18  5:06   ` malc
  0 siblings, 0 replies; 3+ messages in thread
From: malc @ 2011-10-18  5:06 UTC (permalink / raw)
  To: Stefan Weil; +Cc: qemu-trivial, Jes Sorensen, qemu-devel, Trevor Saunders

On Tue, 18 Oct 2011, Stefan Weil wrote:

> Am 18.10.2011 04:06, schrieb Trevor Saunders:
> > strncpy() doesn't garentee the copied string will be null terminated if
> > the original is longer than the length to copy.
> > 
> > Signed-off-by: Trevor Saunders<trev.saunders@gmail.com>
> > ---
> >   os-posix.c |    2 +-
> >   1 files changed, 1 insertions(+), 1 deletions(-)
> > 
> > diff --git a/os-posix.c b/os-posix.c
> > index dbf3b24..92dcc97 100644
> > --- a/os-posix.c
> > +++ b/os-posix.c
> > @@ -149,8 +149,8 @@ void os_set_proc_name(const char *s)
> >       char name[16];
> >       if (!s)
> >           return;
> > -    name[sizeof(name) - 1] = 0;
> >       strncpy(name, s, sizeof(name));
> > +    name[sizeof(name) - 1] = 0;
> >       /* Could rewrite argv[0] too, but that's a bit more complicated.
> >          This simple way is enough for `top'. */
> >       if (prctl(PR_SET_NAME, name)) {
> 
> Reviewed-by: Stefan Weil <sw@weilnetz.de>

cutils.c has pstrcpy for that.

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-10-18  5:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-18  2:06 [Qemu-devel] [PATCH] correctly null terminate the process name Trevor Saunders
2011-10-18  4:19 ` Stefan Weil
2011-10-18  5:06   ` malc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).