Source-Changes-HG archive

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

[src/trunk]: src/sys/compat use strlcpy() for the uts conversion, makes the c...



details:   https://anonhg.NetBSD.org/src/rev/47e4c8303562
branches:  trunk
changeset: 845954:47e4c8303562
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Oct 26 11:34:48 2019 +0000

description:
use strlcpy() for the uts conversion, makes the code simpler and more readable.

diffstat:

 sys/compat/sunos/sunos_misc.c     |  18 ++++++++----------
 sys/compat/sunos32/sunos32_misc.c |  18 ++++++++----------
 2 files changed, 16 insertions(+), 20 deletions(-)

diffs (80 lines):

diff -r b1662c96fc07 -r 47e4c8303562 sys/compat/sunos/sunos_misc.c
--- a/sys/compat/sunos/sunos_misc.c     Sat Oct 26 10:10:14 2019 +0000
+++ b/sys/compat/sunos/sunos_misc.c     Sat Oct 26 11:34:48 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sunos_misc.c,v 1.175 2019/10/04 12:24:12 mrg Exp $     */
+/*     $NetBSD: sunos_misc.c,v 1.176 2019/10/26 11:34:48 christos Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos_misc.c,v 1.175 2019/10/04 12:24:12 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunos_misc.c,v 1.176 2019/10/26 11:34:48 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -653,15 +653,13 @@
 
        memset(&sut, 0, sizeof(sut));
 
-       memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
-       memcpy(sut.nodename, hostname, sizeof(sut.nodename));
-       sut.nodename[sizeof(sut.nodename)-1] = '\0';
-       memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
-       sut.version[0] = '1';
-       memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
+       strlcpy(sut.sysname, ostype, sizeof(sut.sysname));
+       strlcpy(sut.nodename, hostname, sizeof(sut.nodename));
+       strlcpy(sut.release, osrelease, sizeof(sut.release));
+       strlcpy(sut.version, "1", sizeof(sut.version));
+       strlcpy(sut.machine, machine, sizeof(sut.machine));
 
-       return copyout((void *)&sut, (void *)SCARG(uap, name),
-           sizeof(struct sunos_utsname));
+       return copyout(&sut, SCARG(uap, name), sizeof(sut));
 }
 
 int
diff -r b1662c96fc07 -r 47e4c8303562 sys/compat/sunos32/sunos32_misc.c
--- a/sys/compat/sunos32/sunos32_misc.c Sat Oct 26 10:10:14 2019 +0000
+++ b/sys/compat/sunos32/sunos32_misc.c Sat Oct 26 11:34:48 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sunos32_misc.c,v 1.82 2019/09/23 21:07:39 christos Exp $       */
+/*     $NetBSD: sunos32_misc.c,v 1.83 2019/10/26 11:34:48 christos Exp $       */
 /* from :NetBSD: sunos_misc.c,v 1.107 2000/12/01 19:25:10 jdolecek Exp */
 
 /*
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.82 2019/09/23 21:07:39 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunos32_misc.c,v 1.83 2019/10/26 11:34:48 christos Exp $");
 
 #define COMPAT_SUNOS 1
 
@@ -926,15 +926,13 @@
 
        memset(&sut, 0, sizeof(sut));
 
-       memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
-       memcpy(sut.nodename, hostname, sizeof(sut.nodename));
-       sut.nodename[sizeof(sut.nodename)-1] = '\0';
-       memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
-       memcpy(sut.version, "1", sizeof(sut.version) - 1);
-       memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
+       strlcpy(sut.sysname, ostype, sizeof(sut.sysname));
+       strlcpy(sut.nodename, hostname, sizeof(sut.nodename));
+       strlcpy(sut.release, osrelease, sizeof(sut.release));
+       strlcpy(sut.version, "1", sizeof(sut.version));
+       strlcpy(sut.machine, machine, sizeof(sut.machine));
 
-       return copyout((void *)&sut, SCARG_P32(uap, name),
-           sizeof(struct sunos_utsname));
+       return copyout(&sut, SCARG_P32(uap, name), sizeof(sut));
 }
 
 int



Home | Main Index | Thread Index | Old Index