Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat convert strcpy to a bounded copy to avoid compile...



details:   https://anonhg.NetBSD.org/src/rev/04ea6216930e
branches:  trunk
changeset: 820699:04ea6216930e
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jan 13 20:24:37 2017 +0000

description:
convert strcpy to a bounded copy to avoid compiler warnings, although the
reclen test prevents overflow.

diffstat:

 sys/compat/common/vfs_syscalls_43.c  |  7 ++++---
 sys/compat/linux/common/linux_misc.c |  7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diffs (56 lines):

diff -r 8aefcda65f4f -r 04ea6216930e sys/compat/common/vfs_syscalls_43.c
--- a/sys/compat/common/vfs_syscalls_43.c       Fri Jan 13 20:10:57 2017 +0000
+++ b/sys/compat/common/vfs_syscalls_43.c       Fri Jan 13 20:24:37 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_syscalls_43.c,v 1.58 2016/08/20 00:34:42 mrg Exp $ */
+/*     $NetBSD: vfs_syscalls_43.c,v 1.59 2017/01/13 20:25:35 christos Exp $    */
 
 /*
  * Copyright (c) 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.58 2016/08/20 00:34:42 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_43.c,v 1.59 2017/01/13 20:25:35 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -475,7 +475,8 @@
                idb.d_fileno = (uint32_t)bdp->d_fileno;
                idb.d_reclen = (uint16_t)old_reclen;
                idb.d_namlen = (uint16_t)bdp->d_namlen;
-               strcpy(idb.d_name, bdp->d_name);
+               memcpy(idb.d_name, bdp->d_name, MIN(sizeof(idb.d_name),
+                   idb.d_namlen));
                if ((error = copyout(&idb, outp, old_reclen)))
                        goto out;
                /* advance past this real entry */
diff -r 8aefcda65f4f -r 04ea6216930e sys/compat/linux/common/linux_misc.c
--- a/sys/compat/linux/common/linux_misc.c      Fri Jan 13 20:10:57 2017 +0000
+++ b/sys/compat/linux/common/linux_misc.c      Fri Jan 13 20:24:37 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_misc.c,v 1.234 2017/01/02 16:32:10 manu Exp $    */
+/*     $NetBSD: linux_misc.c,v 1.235 2017/01/13 20:24:37 christos Exp $        */
 
 /*-
  * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.234 2017/01/02 16:32:10 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.235 2017/01/13 20:24:37 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -787,7 +787,8 @@
                        /* Linux puts d_type at the end of each record */
                        *((char *)&idb + idb.d_reclen - 1) = bdp->d_type;
                }
-               strcpy(idb.d_name, bdp->d_name);
+               memcpy(idb.d_name, bdp->d_name,
+                   MIN(sizeof(idb.d_name), idb.d_namlen));
                if ((error = copyout((void *)&idb, outp, linux_reclen)))
                        goto out;
                /* advance past this real entry */



Home | Main Index | Thread Index | Old Index