Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern use strlcpy. [fixed off-by-one in subr_prop.c]
details: https://anonhg.NetBSD.org/src/rev/3993ce6fefcd
branches: trunk
changeset: 547280:3993ce6fefcd
user: itojun <itojun%NetBSD.org@localhost>
date: Fri May 16 14:25:02 2003 +0000
description:
use strlcpy. [fixed off-by-one in subr_prop.c]
diffstat:
sys/kern/core_elf32.c | 6 +++---
sys/kern/exec_script.c | 8 ++++----
sys/kern/kern_ksyms.c | 20 ++++++++++++--------
sys/kern/kern_resource.c | 11 ++++++-----
sys/kern/kern_subr.c | 6 +++---
sys/kern/subr_devsw.c | 7 ++++---
sys/kern/subr_prop.c | 19 ++++++++++---------
sys/kern/uipc_sem.c | 4 ++--
sys/kern/vfs_syscalls.c | 13 ++++++++-----
9 files changed, 52 insertions(+), 42 deletions(-)
diffs (truncated from 321 to 300 lines):
diff -r cfe90d7394da -r 3993ce6fefcd sys/kern/core_elf32.c
--- a/sys/kern/core_elf32.c Fri May 16 14:19:49 2003 +0000
+++ b/sys/kern/core_elf32.c Fri May 16 14:25:02 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: core_elf32.c,v 1.6 2003/05/08 20:26:40 matt Exp $ */
+/* $NetBSD: core_elf32.c,v 1.7 2003/05/16 14:25:02 itojun Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.6 2003/05/08 20:26:40 matt Exp $");
+__KERNEL_RCSID(1, "$NetBSD: core_elf32.c,v 1.7 2003/05/16 14:25:02 itojun Exp $");
/* If not included by core_elf64.c, ELFSIZE won't be defined. */
#ifndef ELFSIZE
@@ -329,7 +329,7 @@
cpi.cpi_svgid = p->p_cred->p_svgid;
cpi.cpi_nlwps = p->p_nlwps;
- strcpy(cpi.cpi_name, p->p_comm);
+ strlcpy(cpi.cpi_name, p->p_comm, sizeof(cpi.cpi_name));
nhdr.n_namesz = sizeof(ELF_NOTE_NETBSD_CORE_NAME);
nhdr.n_descsz = sizeof(cpi);
diff -r cfe90d7394da -r 3993ce6fefcd sys/kern/exec_script.c
--- a/sys/kern/exec_script.c Fri May 16 14:19:49 2003 +0000
+++ b/sys/kern/exec_script.c Fri May 16 14:25:02 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_script.c,v 1.33 2003/04/02 01:00:20 perry Exp $ */
+/* $NetBSD: exec_script.c,v 1.34 2003/05/16 14:25:03 itojun Exp $ */
/*
* Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.33 2003/04/02 01:00:20 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.34 2003/05/16 14:25:03 itojun Exp $");
#if defined(SETUIDSCRIPTS) && !defined(FDSCRIPTS)
#define FDSCRIPTS /* Need this for safe set-id scripts. */
@@ -205,10 +205,10 @@
MALLOC(shellargp, char **, 4 * sizeof(char *), M_EXEC, M_WAITOK);
tmpsap = shellargp;
MALLOC(*tmpsap, char *, shellnamelen + 1, M_EXEC, M_WAITOK);
- strcpy(*tmpsap++, shellname);
+ strlcpy(*tmpsap++, shellname, shellnamelen + 1);
if (shellarg != NULL) {
MALLOC(*tmpsap, char *, shellarglen + 1, M_EXEC, M_WAITOK);
- strcpy(*tmpsap++, shellarg);
+ strlcpy(*tmpsap++, shellarg, shellarglen + 1);
}
MALLOC(*tmpsap, char *, MAXPATHLEN, M_EXEC, M_WAITOK);
#ifdef FDSCRIPTS
diff -r cfe90d7394da -r 3993ce6fefcd sys/kern/kern_ksyms.c
--- a/sys/kern/kern_ksyms.c Fri May 16 14:19:49 2003 +0000
+++ b/sys/kern/kern_ksyms.c Fri May 16 14:25:02 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_ksyms.c,v 1.9 2003/05/11 08:23:23 jdolecek Exp $ */
+/* $NetBSD: kern_ksyms.c,v 1.10 2003/05/16 14:25:03 itojun Exp $ */
/*
* Copyright (c) 2001, 2003 Anders Magnusson (ragge%ludd.luth.se@localhost).
* All rights reserved.
@@ -393,7 +393,7 @@
str[0] = 0;
n = 1;
for (i = 1; i < tab->sd_symsize/sizeof(Elf_Sym); i++) {
- strcpy(str+n, tab->sd_strstart + sym[i].st_name);
+ strcpy(str + n, tab->sd_strstart + sym[i].st_name);
sym[i].st_name = n;
n += strlen(str+n) + 1;
}
@@ -621,7 +621,7 @@
printf("addsym: too many sumbols, skipping '%s'\n", name);
return;
}
- strcpy(&symnames[curnamep], name);
+ strlcpy(&symnames[curnamep], name, sizeof(symnames) - curnamep);
savedsyms[cursyms] = *sym;
symnmoff[cursyms] = savedsyms[cursyms].st_name = curnamep;
curnamep += len;
@@ -705,8 +705,9 @@
memcpy(str, symnames, curnamep);
st = malloc(sizeof(struct symtab), M_DEVBUF, M_WAITOK);
- name = malloc(strlen(mod)+1, M_DEVBUF, M_WAITOK);
- strcpy(name, mod);
+ i = strlen(mod) + 1;
+ name = malloc(i, M_DEVBUF, M_WAITOK);
+ strlcpy(name, mod, i);
st->sd_name = name;
st->sd_symnmoff = malloc(sizeof(int)*cursyms, M_DEVBUF, M_WAITOK);
memcpy(st->sd_symnmoff, symnmoff, sizeof(int)*cursyms);
@@ -895,9 +896,12 @@
ksyms_hdr.kh_shdr[SHSTRTAB].sh_addralign = sizeof(char);
/* Set section names */
- strcpy(&ksyms_hdr.kh_strtab[1], ".symtab");
- strcpy(&ksyms_hdr.kh_strtab[9], ".strtab");
- strcpy(&ksyms_hdr.kh_strtab[17], ".shstrtab");
+ strlcpy(&ksyms_hdr.kh_strtab[1], ".symtab",
+ sizeof(ksyms_hdr.kh_strtab) - 1);
+ strlcpy(&ksyms_hdr.kh_strtab[9], ".strtab",
+ sizeof(ksyms_hdr.kh_strtab) - 9);
+ strlcpy(&ksyms_hdr.kh_strtab[17], ".shstrtab",
+ sizeof(ksyms_hdr.kh_strtab) - 17);
};
int
diff -r cfe90d7394da -r 3993ce6fefcd sys/kern/kern_resource.c
--- a/sys/kern/kern_resource.c Fri May 16 14:19:49 2003 +0000
+++ b/sys/kern/kern_resource.c Fri May 16 14:25:02 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_resource.c,v 1.70 2003/03/14 21:38:26 dsl Exp $ */
+/* $NetBSD: kern_resource.c,v 1.71 2003/05/16 14:25:03 itojun Exp $ */
/*-
* Copyright (c) 1982, 1986, 1991, 1993
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.70 2003/03/14 21:38:26 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_resource.c,v 1.71 2003/05/16 14:25:03 itojun Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -503,6 +503,7 @@
struct plimit *lim;
{
struct plimit *newlim;
+ size_t l;
newlim = pool_get(&plimit_pool, PR_WAITOK);
memcpy(newlim->pl_rlimit, lim->pl_rlimit,
@@ -510,9 +511,9 @@
if (lim->pl_corename == defcorename) {
newlim->pl_corename = defcorename;
} else {
- newlim->pl_corename = malloc(strlen(lim->pl_corename)+1,
- M_TEMP, M_WAITOK);
- strcpy(newlim->pl_corename, lim->pl_corename);
+ l = strlen(lim->pl_corename) + 1;
+ newlim->pl_corename = malloc(l, M_TEMP, M_WAITOK);
+ strlcpy(newlim->pl_corename, lim->pl_corename, l);
}
newlim->p_lflags = 0;
newlim->p_refcnt = 1;
diff -r cfe90d7394da -r 3993ce6fefcd sys/kern/kern_subr.c
--- a/sys/kern/kern_subr.c Fri May 16 14:19:49 2003 +0000
+++ b/sys/kern/kern_subr.c Fri May 16 14:25:02 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_subr.c,v 1.98 2003/05/15 12:56:16 dsl Exp $ */
+/* $NetBSD: kern_subr.c,v 1.99 2003/05/16 14:25:03 itojun Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.98 2003/05/15 12:56:16 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.99 2003/05/16 14:25:03 itojun Exp $");
#include "opt_ddb.h"
#include "opt_md.h"
@@ -814,7 +814,7 @@
printf(": ");
len = cngetsn(buf, sizeof(buf));
if (len == 0 && bootdv != NULL) {
- strcpy(buf, bootdv->dv_xname);
+ strlcpy(buf, bootdv->dv_xname, sizeof(buf));
len = strlen(buf);
}
if (len > 0 && buf[len - 1] == '*') {
diff -r cfe90d7394da -r 3993ce6fefcd sys/kern/subr_devsw.c
--- a/sys/kern/subr_devsw.c Fri May 16 14:19:49 2003 +0000
+++ b/sys/kern/subr_devsw.c Fri May 16 14:25:02 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_devsw.c,v 1.5 2003/02/01 11:12:35 mrg Exp $ */
+/* $NetBSD: subr_devsw.c,v 1.6 2003/05/16 14:25:03 itojun Exp $ */
/*-
* Copyright (c) 2001,2002 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -140,12 +140,13 @@
max_devsw_convs = new;
}
- name = malloc(strlen(devname) + 1, M_DEVBUF, M_NOWAIT);
+ i = strlen(devname) + 1;
+ name = malloc(i, M_DEVBUF, M_NOWAIT);
if (name == NULL) {
devsw_detach(bdev, cdev);
return (ENOMEM);
}
- strcpy(name, devname);
+ strlcpy(name, devname, i);
devsw_conv[i].d_name = name;
devsw_conv[i].d_bmajor = *bmajor;
diff -r cfe90d7394da -r 3993ce6fefcd sys/kern/subr_prop.c
--- a/sys/kern/subr_prop.c Fri May 16 14:19:49 2003 +0000
+++ b/sys/kern/subr_prop.c Fri May 16 14:25:02 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_prop.c,v 1.9 2003/02/01 06:23:44 thorpej Exp $ */
+/* $NetBSD: subr_prop.c,v 1.10 2003/05/16 14:25:03 itojun Exp $ */
/*
* Copyright (c) 2001 Eduardo Horvath.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_prop.c,v 1.9 2003/02/01 06:23:44 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_prop.c,v 1.10 2003/05/16 14:25:03 itojun Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -136,7 +136,7 @@
vp = (char *)&kp[1];
kp->kp_val = (const char *)vp;
np = vp + dsize;
- strcpy(np, name);
+ strlcpy(np, name, nsize);
kp->kp_name = (const char *)np;
kp->kp_len = len;
}
@@ -486,8 +486,8 @@
{
struct kdbobj *obj;
struct kdbprop *prop = NULL;
- size_t total_len = 0;
int s, i = 0;
+ char *sp, *ep;
DPRINTF(x, ("prop_list: %p, %p, %p, %lx\n",
db, object, names, (unsigned long)len));
@@ -500,18 +500,19 @@
return (0);
}
+ sp = names;
+ ep = names + len;
LIST_FOREACH(prop, &obj->ko_props, kp_link) {
i = strlen(prop->kp_name) + 1;
- total_len += i;
- if (total_len < len) {
- strcpy(names, prop->kp_name);
+ if (names + i + 1 < ep) {
+ strlcpy(names, prop->kp_name, ep - names);
names += i;
/* Add an extra NUL */
- names[i+1] = 0;
+ names[i + 1] = 0;
}
}
splx(s);
- return (total_len);
+ return (names - sp);
}
int
diff -r cfe90d7394da -r 3993ce6fefcd sys/kern/uipc_sem.c
--- a/sys/kern/uipc_sem.c Fri May 16 14:19:49 2003 +0000
+++ b/sys/kern/uipc_sem.c Fri May 16 14:25:02 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_sem.c,v 1.5 2003/04/23 17:50:51 matt Exp $ */
+/* $NetBSD: uipc_sem.c,v 1.6 2003/05/16 14:25:03 itojun Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -274,7 +274,7 @@
return (EINVAL);
}
ret->ks_name = malloc(len + 1, M_SEM, M_WAITOK);
- strcpy(ret->ks_name, name);
+ strlcpy(ret->ks_name, name, len + 1);
} else
ret->ks_name = NULL;
ret->ks_mode = mode;
diff -r cfe90d7394da -r 3993ce6fefcd sys/kern/vfs_syscalls.c
--- a/sys/kern/vfs_syscalls.c Fri May 16 14:19:49 2003 +0000
+++ b/sys/kern/vfs_syscalls.c Fri May 16 14:25:02 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_syscalls.c,v 1.186 2003/04/20 07:06:33 yamt Exp $ */
+/* $NetBSD: vfs_syscalls.c,v 1.187 2003/05/16 14:25:03 itojun Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.186 2003/04/20 07:06:33 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.187 2003/05/16 14:25:03 itojun Exp $");
Home |
Main Index |
Thread Index |
Old Index