Skip to contentSkip to conversation

correctly null terminate the process name

PATCH In review Trevor Saunders 3 participants 3 messages Oct 18, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 correctly null terminate the process name

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

---
 os-posix.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
os-posix.c +1 -1
index dbf3b24..92dcc97 100644
@@ -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)) {
Signature · 1 line
1.7.7
Reviewed-by on v1 1/1
#1 lore raw

Am 18.10.2011 04:06, schrieb Trevor Saunders:

Quoted 13 lines

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

---
  os-posix.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
os-posix.c +0 -0
index dbf3b24..92dcc97 100644

os-posix.c void os_set_proc_name(const char *s) · line 156

Quoted 9 lines
os-posix.c +1 -1
@@ -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)) {
#2 lore raw
Quoted 9 lines · Stefan Weil

Am 18.10.2011 04:06, schrieb Trevor Saunders:

Quoted 8 lines

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

---
  os-posix.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 16 lines
Quoted 5 lines
os-posix.c +0 -0
index dbf3b24..92dcc97 100644

os-posix.c void os_set_proc_name(const char *s) · line 156

Quoted 9 lines
os-posix.c +1 -1
@@ -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)) {

cutils.c has pstrcpy for that.

Signature · 1 line
mailto:[email protected]