]> xenbits.xensource.com Git - qemu-upstream-4.4-testing.git/commitdiff
os-posix: avoid buffer overrun
authorJim Meyering <meyering@redhat.com>
Thu, 4 Oct 2012 11:09:51 +0000 (13:09 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 5 Oct 2012 12:58:37 +0000 (07:58 -0500)
os_set_proc_name: Use pstrcpy, in place of strncpy and the
ineffectual preceding assignment: name[sizeof(name) - 1] = 0;

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
os-posix.c

index eabccb8fe051c79bfd8764d4e514d22520d744e5..f855abb09a2d2ad4cfea51e170e8b2f69cbd078c 100644 (file)
@@ -148,8 +148,7 @@ void os_set_proc_name(const char *s)
     char name[16];
     if (!s)
         return;
-    name[sizeof(name) - 1] = 0;
-    strncpy(name, s, sizeof(name));
+    pstrcpy(name, sizeof(name), s);
     /* 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)) {