summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJean-Francois Brousseau <jfb@cvs.openbsd.org>2004-06-22 23:52:19 +0000
committerJean-Francois Brousseau <jfb@cvs.openbsd.org>2004-06-22 23:52:19 +0000
commit68fe655b77ab978f8d03f8feec46801220bd46c5 (patch)
treecf71e1513645d4dd977c3b1b4a92d6ec1578c8f6 /sys
parent5557b30319fbfe74844a640472fa29a826d1be8b (diff)
Replace a whole bunch of scary uses of strncpy() with strlcpy() and
use compat-specific MAXNAMLEN values where appropriate ok millert@, pedro@
Diffstat (limited to 'sys')
-rw-r--r--sys/compat/common/kern_info_09.c10
-rw-r--r--sys/compat/hpux/hpux_compat.c16
-rw-r--r--sys/compat/ibcs2/ibcs2_misc.c4
-rw-r--r--sys/compat/linux/linux_getcwd.c5
-rw-r--r--sys/compat/linux/linux_misc.c40
-rw-r--r--sys/compat/osf1/osf1_exec.c4
-rw-r--r--sys/compat/osf1/osf1_misc.c17
-rw-r--r--sys/compat/sunos/sunos_misc.c4
-rw-r--r--sys/compat/svr4/svr4_misc.c6
-rw-r--r--sys/compat/svr4/svr4_sockio.c4
-rw-r--r--sys/compat/svr4/svr4_stat.c17
-rw-r--r--sys/compat/ultrix/ultrix_fs.c7
12 files changed, 55 insertions, 79 deletions
diff --git a/sys/compat/common/kern_info_09.c b/sys/compat/common/kern_info_09.c
index 38889b8757a..4686b9fba4d 100644
--- a/sys/compat/common/kern_info_09.c
+++ b/sys/compat/common/kern_info_09.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_info_09.c,v 1.11 2003/08/15 20:32:15 tedu Exp $ */
+/* $OpenBSD: kern_info_09.c,v 1.12 2004/06/22 23:52:17 jfb Exp $ */
/* $NetBSD: kern_info_09.c,v 1.5 1996/02/21 00:10:59 cgd Exp $ */
/*
@@ -113,9 +113,9 @@ compat_09_sys_uname(p, v, retval)
const char *cp;
char *dp, *ep;
- strncpy(outsname.sysname, ostype, sizeof(outsname.sysname));
- strncpy(outsname.nodename, hostname, sizeof(outsname.nodename));
- strncpy(outsname.release, osrelease, sizeof(outsname.release));
+ strlcpy(outsname.sysname, ostype, sizeof(outsname.sysname));
+ strlcpy(outsname.nodename, hostname, sizeof(outsname.nodename));
+ strlcpy(outsname.release, osrelease, sizeof(outsname.release));
dp = outsname.version;
ep = &outsname.version[sizeof(outsname.version) - 1];
for (cp = version; *cp && *cp != '('; cp++)
@@ -127,7 +127,7 @@ compat_09_sys_uname(p, v, retval)
for (; *cp && *cp != ':' && dp < ep; cp++)
*dp++ = *cp;
*dp = '\0';
- strncpy(outsname.machine, MACHINE, sizeof(outsname.machine));
+ strlcpy(outsname.machine, MACHINE, sizeof(outsname.machine));
return (copyout((caddr_t)&outsname, (caddr_t)SCARG(uap, name),
sizeof(struct outsname)));
diff --git a/sys/compat/hpux/hpux_compat.c b/sys/compat/hpux/hpux_compat.c
index 792fef3a4d5..cfd8a766e89 100644
--- a/sys/compat/hpux/hpux_compat.c
+++ b/sys/compat/hpux/hpux_compat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hpux_compat.c,v 1.25 2004/06/21 23:50:35 tholo Exp $ */
+/* $OpenBSD: hpux_compat.c,v 1.26 2004/06/22 23:52:17 jfb Exp $ */
/* $NetBSD: hpux_compat.c,v 1.35 1997/05/08 16:19:48 mycroft Exp $ */
/*
@@ -392,22 +392,16 @@ hpux_sys_utssys(p, v, retval)
case 0:
bzero(&ut, sizeof(ut));
- strncpy(ut.sysname, ostype, sizeof(ut.sysname));
- ut.sysname[sizeof(ut.sysname) - 1] = '\0';
+ strlcpy(ut.sysname, ostype, sizeof(ut.sysname));
/* copy hostname (sans domain) to nodename */
for (i = 0; i < 8 && hostname[i] != '.'; i++)
ut.nodename[i] = hostname[i];
ut.nodename[i] = '\0';
- strncpy(ut.release, osrelease, sizeof(ut.release));
- ut.release[sizeof(ut.release) - 1] = '\0';
-
- strncpy(ut.version, version, sizeof(ut.version));
- ut.version[sizeof(ut.version) - 1] = '\0';
-
- strncpy(ut.machine, machine, sizeof(ut.machine));
- ut.machine[sizeof(ut.machine) - 1] = '\0';
+ strlcpy(ut.release, osrelease, sizeof(ut.release));
+ strlcpy(ut.version, version, sizeof(ut.version));
+ strlcpy(ut.machine, machine, sizeof(ut.machine));
error = copyout((caddr_t)&ut,
(caddr_t)SCARG(uap, uts), sizeof(ut));
diff --git a/sys/compat/ibcs2/ibcs2_misc.c b/sys/compat/ibcs2/ibcs2_misc.c
index 681bf21baad..af26fd91cd7 100644
--- a/sys/compat/ibcs2/ibcs2_misc.c
+++ b/sys/compat/ibcs2/ibcs2_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ibcs2_misc.c,v 1.27 2003/08/15 20:32:15 tedu Exp $ */
+/* $OpenBSD: ibcs2_misc.c,v 1.28 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD: ibcs2_misc.c,v 1.23 1997/01/15 01:37:49 perry Exp $ */
/*
@@ -364,7 +364,7 @@ ibcs2_readdir_callback(arg, bdp, cookie)
idb.d_pad = 0;
idb.d_off = (ibcs2_off_t)cookie;
idb.d_reclen = (u_short)ibcs2_reclen;
- strlcpy(idb.d_name, bdp->d_name, IBCS2_MAXNAMLEN+1);
+ strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
error = copyout((caddr_t)&idb, cb->outp, ibcs2_reclen);
if (error)
return (error);
diff --git a/sys/compat/linux/linux_getcwd.c b/sys/compat/linux/linux_getcwd.c
index 1f799433c4e..09ffc5404b7 100644
--- a/sys/compat/linux/linux_getcwd.c
+++ b/sys/compat/linux/linux_getcwd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_getcwd.c,v 1.3 2002/03/14 01:26:50 millert Exp $ */
+/* $OpenBSD: linux_getcwd.c,v 1.4 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD: vfs_getcwd.c,v 1.3.2.3 1999/07/11 10:24:09 sommerfeld Exp $ */
/*-
@@ -59,6 +59,7 @@ int proc_isunder(struct proc *, struct proc*); /* missing from proc.h */
#include <compat/linux/linux_signal.h>
#include <compat/linux/linux_syscallargs.h>
#include <compat/linux/linux_util.h>
+#include <compat/linux/linux_dirent.h>
#include <machine/linux_machdep.h>
@@ -75,7 +76,7 @@ linux_getcwd_common(struct vnode *, struct vnode *,
static int
linux_vn_isunder(struct vnode *, struct vnode *, struct proc *);
-#define DIRENT_MINSIZE (sizeof(struct dirent) - (MAXNAMLEN+1) + 4)
+#define DIRENT_MINSIZE (sizeof(struct dirent) - (LINUX_MAXNAMLEN+1) + 4)
/*
* Vnode variable naming conventions in this file:
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c
index 0c31e2d1d28..22062458206 100644
--- a/sys/compat/linux/linux_misc.c
+++ b/sys/compat/linux/linux_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_misc.c,v 1.55 2003/12/02 03:46:45 nordin Exp $ */
+/* $OpenBSD: linux_misc.c,v 1.56 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD: linux_misc.c,v 1.27 1996/05/20 01:59:21 fvdl Exp $ */
/*-
@@ -520,18 +520,12 @@ linux_sys_uname(p, v, retval)
int len;
char *cp;
- strncpy(luts.l_sysname, ostype, sizeof(luts.l_sysname) - 1);
- luts.l_sysname[sizeof(luts.l_sysname) - 1] = '\0';
- strncpy(luts.l_nodename, hostname, sizeof(luts.l_nodename) - 1);
- luts.l_nodename[sizeof(luts.l_nodename) - 1] = '\0';
- strncpy(luts.l_release, osrelease, sizeof(luts.l_release) - 1);
- luts.l_release[sizeof(luts.l_release) - 1] = '\0';
- strncpy(luts.l_version, version, sizeof(luts.l_version) - 1);
- luts.l_version[sizeof(luts.l_version) - 1] = '\0';
- strncpy(luts.l_machine, machine, sizeof(luts.l_machine) - 1);
- luts.l_machine[sizeof(luts.l_machine) - 1] = '\0';
- strncpy(luts.l_domainname, domainname, sizeof(luts.l_domainname) - 1);
- luts.l_domainname[sizeof(luts.l_domainname) - 1] = '\0';
+ strlcpy(luts.l_sysname, ostype, sizeof(luts.l_sysname));
+ strlcpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
+ strlcpy(luts.l_release, osrelease, sizeof(luts.l_release));
+ strlcpy(luts.l_version, version, sizeof(luts.l_version));
+ strlcpy(luts.l_machine, machine, sizeof(luts.l_machine));
+ strlcpy(luts.l_domainname, domainname, sizeof(luts.l_domainname));
/* This part taken from the the uname() in libc */
len = sizeof(luts.l_version);
@@ -556,11 +550,11 @@ linux_sys_olduname(p, v, retval)
int len;
char *cp;
- strncpy(luts.l_sysname, ostype, sizeof(luts.l_sysname));
- strncpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
- strncpy(luts.l_release, osrelease, sizeof(luts.l_release));
- strncpy(luts.l_version, version, sizeof(luts.l_version));
- strncpy(luts.l_machine, machine, sizeof(luts.l_machine));
+ strlcpy(luts.l_sysname, ostype, sizeof(luts.l_sysname));
+ strlcpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
+ strlcpy(luts.l_release, osrelease, sizeof(luts.l_release));
+ strlcpy(luts.l_version, version, sizeof(luts.l_version));
+ strlcpy(luts.l_machine, machine, sizeof(luts.l_machine));
/* This part taken from the the uname() in libc */
len = sizeof(luts.l_version);
@@ -585,11 +579,11 @@ linux_sys_oldolduname(p, v, retval)
int len;
char *cp;
- strncpy(luts.l_sysname, ostype, sizeof(luts.l_sysname));
- strncpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
- strncpy(luts.l_release, osrelease, sizeof(luts.l_release));
- strncpy(luts.l_version, version, sizeof(luts.l_version));
- strncpy(luts.l_machine, machine, sizeof(luts.l_machine));
+ strlcpy(luts.l_sysname, ostype, sizeof(luts.l_sysname));
+ strlcpy(luts.l_nodename, hostname, sizeof(luts.l_nodename));
+ strlcpy(luts.l_release, osrelease, sizeof(luts.l_release));
+ strlcpy(luts.l_version, version, sizeof(luts.l_version));
+ strlcpy(luts.l_machine, machine, sizeof(luts.l_machine));
/* This part taken from the the uname() in libc */
len = sizeof(luts.l_version);
diff --git a/sys/compat/osf1/osf1_exec.c b/sys/compat/osf1/osf1_exec.c
index 30858fb9e19..7e30538baa8 100644
--- a/sys/compat/osf1/osf1_exec.c
+++ b/sys/compat/osf1/osf1_exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: osf1_exec.c,v 1.4 2002/03/14 01:26:50 millert Exp $ */
+/* $OpenBSD: osf1_exec.c,v 1.5 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD$ */
/*
@@ -238,7 +238,7 @@ osf1_exec_ecoff_dynamic(struct proc *p, struct exec_package *epp)
error = emul_find(p, NULL, osf1_emul_path,
OSF1_LDR_EXEC_DEFAULT_LOADER, &pathbuf, 0);
/* includes /emul/osf1 if appropriate */
- strncpy(emul_arg->loader_name, pathbuf, MAXPATHLEN + 1);
+ strlcpy(emul_arg->loader_name, pathbuf, sizeof(emul_arg->loader_name));
emul_arg->flags |= OSF1_EXEC_EMUL_FLAGS_HAVE_LOADER;
if (!error)
free((char *)pathbuf, M_TEMP);
diff --git a/sys/compat/osf1/osf1_misc.c b/sys/compat/osf1/osf1_misc.c
index de227667a5c..3c94c5b17d7 100644
--- a/sys/compat/osf1/osf1_misc.c
+++ b/sys/compat/osf1/osf1_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: osf1_misc.c,v 1.14 2002/03/14 20:31:31 mickey Exp $ */
+/* $OpenBSD: osf1_misc.c,v 1.15 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD: osf1_misc.c,v 1.55 2000/06/28 15:39:33 mrg Exp $ */
/*
@@ -246,15 +246,9 @@ osf1_sys_uname(p, v, retval)
/* XXX would use stackgap, but our struct utsname is too big! */
bzero(&u, sizeof(u));
-
- strncpy(u.sysname, ostype, sizeof(u.sysname));
- u.sysname[sizeof(u.sysname) - 1] = '\0';
-
- strncpy(u.nodename, hostname, sizeof(u.nodename));
- u.nodename[sizeof(u.nodename) - 1] = '\0';
-
- strncpy(u.release, osrelease, sizeof(u.release));
- u.release[sizeof(u.release) - 1] = '\0';
+ strlcpy(u.sysname, ostype, sizeof(u.sysname));
+ strlcpy(u.nodename, hostname, sizeof(u.nodename));
+ strlcpy(u.release, osrelease, sizeof(u.release));
dp = u.version;
ep = &u.version[sizeof(u.version) - 1];
@@ -268,8 +262,7 @@ osf1_sys_uname(p, v, retval)
*dp++ = *cp;
*dp = '\0';
- strncpy(u.machine, machine, sizeof(u.machine));
- u.machine[sizeof(u.machine) - 1] = '\0';
+ strlcpy(u.machine, machine, sizeof(u.machine));
return (copyout((caddr_t)&u, (caddr_t)SCARG(uap, name), sizeof u));
}
diff --git a/sys/compat/sunos/sunos_misc.c b/sys/compat/sunos/sunos_misc.c
index 60e2486ed31..df3cf2dc84b 100644
--- a/sys/compat/sunos/sunos_misc.c
+++ b/sys/compat/sunos/sunos_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sunos_misc.c,v 1.44 2004/06/22 20:45:33 deraadt Exp $ */
+/* $OpenBSD: sunos_misc.c,v 1.45 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD: sunos_misc.c,v 1.65 1996/04/22 01:44:31 christos Exp $ */
/*
@@ -400,7 +400,7 @@ sunos_readdir_callback(arg, bdp, cookie)
idb.d_off = cookie;
idb.d_reclen = sunos_reclen;
idb.d_namlen = bdp->d_namlen;
- strlcpy(idb.d_name, bdp->d_name, SUNOS_MAXNAMLEN+1);
+ strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
if ((error = copyout((caddr_t)&idb, cb->outp, sunos_reclen)))
return (error);
diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c
index 6fce7a7d203..f02c0a925b7 100644
--- a/sys/compat/svr4/svr4_misc.c
+++ b/sys/compat/svr4/svr4_misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_misc.c,v 1.43 2003/08/15 20:32:16 tedu Exp $ */
+/* $OpenBSD: svr4_misc.c,v 1.44 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD: svr4_misc.c,v 1.42 1996/12/06 03:22:34 christos Exp $ */
/*
@@ -244,7 +244,7 @@ svr4_readdir_callback(arg, bdp, cookie)
idb.d_ino = (svr4_ino_t)bdp->d_fileno;
idb.d_off = (svr4_off_t)cookie;
idb.d_reclen = (u_short)svr4_reclen;
- strlcpy(idb.d_name, bdp->d_name, SVR4_MAXNAMLEN+1);
+ strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
if ((error = copyout((caddr_t)&idb, cb->outp, svr4_reclen)))
return (error);
@@ -277,7 +277,7 @@ svr4_readdir64_callback(arg, bdp, cookie)
idb.d_ino = (svr4_ino64_t)bdp->d_fileno;
idb.d_off = (svr4_off64_t)cookie;
idb.d_reclen = (u_short)svr4_reclen;
- strlcpy(idb.d_name, bdp->d_name, SVR4_MAXNAMLEN+1);
+ strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
if ((error = copyout((caddr_t)&idb, cb->outp, svr4_reclen)))
return (error);
diff --git a/sys/compat/svr4/svr4_sockio.c b/sys/compat/svr4/svr4_sockio.c
index 7da1c24b450..57f51d512ad 100644
--- a/sys/compat/svr4/svr4_sockio.c
+++ b/sys/compat/svr4/svr4_sockio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_sockio.c,v 1.8 2002/03/14 01:26:51 millert Exp $ */
+/* $OpenBSD: svr4_sockio.c,v 1.9 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD: svr4_sockio.c,v 1.10 1996/05/03 17:09:15 christos Exp $ */
/*
@@ -131,7 +131,7 @@ svr4_sock_ioctl(fp, p, retval, fd, cmd, data)
if ((error = copyin(data, &sr, sizeof(sr))) != 0)
return error;
- (void) strncpy(br.ifr_name, sr.svr4_ifr_name,
+ (void) strlcpy(br.ifr_name, sr.svr4_ifr_name,
sizeof(br.ifr_name));
if ((error = (*ctl)(fp, SIOCGIFFLAGS,
diff --git a/sys/compat/svr4/svr4_stat.c b/sys/compat/svr4/svr4_stat.c
index 077f86817a6..ac7c9623577 100644
--- a/sys/compat/svr4/svr4_stat.c
+++ b/sys/compat/svr4/svr4_stat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svr4_stat.c,v 1.25 2003/08/15 20:32:16 tedu Exp $ */
+/* $OpenBSD: svr4_stat.c,v 1.26 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD: svr4_stat.c,v 1.21 1996/04/22 01:16:07 christos Exp $ */
/*
@@ -528,15 +528,9 @@ svr4_sys_uname(p, v, retval)
char *dp, *ep;
bzero(&sut, sizeof(sut));
-
- strncpy(sut.sysname, ostype, sizeof(sut.sysname)-1);
- sut.sysname[sizeof(sut.sysname) - 1] = '\0';
-
- strncpy(sut.nodename, hostname, sizeof(sut.nodename)-1);
- sut.nodename[sizeof(sut.nodename) - 1] = '\0';
-
- strncpy(sut.release, osrelease, sizeof(sut.release)-1);
- sut.release[sizeof(sut.release) - 1] = '\0';
+ strlcpy(sut.sysname, ostype, sizeof(sut.sysname));
+ strlcpy(sut.nodename, hostname, sizeof(sut.nodename));
+ strlcpy(sut.release, osrelease, sizeof(sut.release));
dp = sut.version;
ep = &sut.version[sizeof(sut.version) - 1];
@@ -550,8 +544,7 @@ svr4_sys_uname(p, v, retval)
*dp++ = *cp;
*dp = '\0';
- strncpy(sut.machine, machine, sizeof(sut.machine)-1);
- sut.machine[sizeof(sut.machine) - 1] = '\0';
+ strlcpy(sut.machine, machine, sizeof(sut.machine));
return copyout((caddr_t) &sut, (caddr_t) SCARG(uap, name),
sizeof(struct svr4_utsname));
diff --git a/sys/compat/ultrix/ultrix_fs.c b/sys/compat/ultrix/ultrix_fs.c
index bd5bcf841ff..d0ee49b5cc2 100644
--- a/sys/compat/ultrix/ultrix_fs.c
+++ b/sys/compat/ultrix/ultrix_fs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ultrix_fs.c,v 1.11 2002/07/20 19:24:57 art Exp $ */
+/* $OpenBSD: ultrix_fs.c,v 1.12 2004/06/22 23:52:18 jfb Exp $ */
/* $NetBSD: ultrix_fs.c,v 1.4 1996/04/07 17:23:06 jonathan Exp $ */
/*
@@ -179,8 +179,9 @@ make_ultrix_mntent(sp, tem)
tem->ufsd_uid = 0; /* XXX kept where ?*/
tem->ufsd_dev = 0; /* ?? */
tem->ufsd_exroot = 0; /* ?? */
- strncpy(tem->ufsd_path, sp->f_mntonname, ULTRIX_MAXPATHLEN);
- strncpy(tem->ufsd_devname, sp->f_mntfromname, ULTRIX_MAXPATHLEN);
+ strlcpy(tem->ufsd_path, sp->f_mntonname, sizeof(tem->ufsd_path));
+ strlcpy(tem->ufsd_devname, sp->f_mntfromname,
+ sizeof(tem->ufsd_devname));
#if 0
/* In NetBSD-1.1, filesystem type is unused and always 0 */
printf("mntent: %s type %d\n", tem->ufsd_devname, tem->ufsd_fstype);