From: deraadt Date: Tue, 22 Feb 2022 17:14:13 +0000 (+0000) Subject: Start using new _MAXCOMLEN (a proper string expanded to 24 bytes X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=633fc60bcca1e84612278ba40d879da28a44004e;p=openbsd Start using new _MAXCOMLEN (a proper string expanded to 24 bytes including the NUL), in all internal interafaces, and expose this in ktrace, core, or proc.h visibility. ok millert --- diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index ab37a18c8dd..bf0e51ca696 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exec.c,v 1.229 2022/02/07 19:30:48 guenther Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.230 2022/02/22 17:14:14 deraadt Exp $ */ /* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- @@ -508,8 +508,7 @@ sys_execve(struct proc *p, void *v, register_t *retval) /* set command name & other accounting info */ memset(pr->ps_comm, 0, sizeof(pr->ps_comm)); - len = min(nid.ni_cnd.cn_namelen, MAXCOMLEN); - memcpy(pr->ps_comm, nid.ni_cnd.cn_nameptr, len); + strlcpy(pr->ps_comm, nid.ni_cnd.cn_nameptr, sizeof(pr->ps_comm)); pr->ps_acflag &= ~AFORK; /* record proc's vnode, for use by sysctl */ diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 23b2af5c88d..e8810fb0264 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_ktrace.c,v 1.105 2021/12/23 18:50:32 guenther Exp $ */ +/* $OpenBSD: kern_ktrace.c,v 1.106 2022/02/22 17:14:14 deraadt Exp $ */ /* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */ /* @@ -141,7 +141,7 @@ ktrinitheader(struct ktr_header *kth, struct proc *p, int type) struct process *pr = p->p_p; ktrinitheaderraw(kth, type, pr->ps_pid, p->p_tid + THREAD_PID_OFFSET); - memcpy(kth->ktr_comm, pr->ps_comm, MAXCOMLEN); + memcpy(kth->ktr_comm, pr->ps_comm, sizeof(kth->ktr_comm)); } int diff --git a/sys/sys/core.h b/sys/sys/core.h index cd69b4123f7..284ef50329f 100644 --- a/sys/sys/core.h +++ b/sys/sys/core.h @@ -1,4 +1,4 @@ -/* $OpenBSD: core.h,v 1.7 2016/09/17 06:09:08 guenther Exp $ */ +/* $OpenBSD: core.h,v 1.8 2022/02/22 17:14:13 deraadt Exp $ */ /* $NetBSD: core.h,v 1.4 1994/10/29 08:20:14 cgd Exp $ */ /* @@ -78,7 +78,7 @@ struct core { u_int16_t c_hdrsize; /* Size of this header (machdep algn) */ u_int16_t c_seghdrsize; /* Size of a segment header */ u_int32_t c_nseg; /* # of core segments */ - char c_name[MAXCOMLEN+1]; /* Copy of p->p_comm */ + char c_name[_MAXCOMLEN]; /* Copy of p->p_comm, incl NUL */ u_int32_t c_signo; /* Killing signal */ u_long c_ucode; /* Hmm ? */ u_long c_cpusize; /* Size of machine dependent segment */ diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index f500e552234..90c8258de9c 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ktrace.h,v 1.40 2021/03/10 10:21:47 jsg Exp $ */ +/* $OpenBSD: ktrace.h,v 1.41 2022/02/22 17:14:14 deraadt Exp $ */ /* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */ /* @@ -33,6 +33,7 @@ */ #include +#include /* * operations to ktrace system call (KTROP(op)) @@ -54,7 +55,7 @@ struct ktr_header { pid_t ktr_pid; /* process id */ pid_t ktr_tid; /* thread id */ struct timespec ktr_time; /* timestamp */ - char ktr_comm[MAXCOMLEN+1]; /* command name */ + char ktr_comm[_MAXCOMLEN]; /* command name, incl NUL */ size_t ktr_len; /* length of buf */ }; diff --git a/sys/sys/proc.h b/sys/sys/proc.h index ce1c451bbcd..6b9ade9c5db 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.326 2022/02/15 23:16:00 rob Exp $ */ +/* $OpenBSD: proc.h,v 1.327 2022/02/22 17:14:14 deraadt Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -212,7 +212,7 @@ struct process { struct plimit *ps_limit; /* [m,R] Process limits. */ struct pgrp *ps_pgrp; /* Pointer to process group. */ - char ps_comm[MAXCOMLEN+1]; + char ps_comm[_MAXCOMLEN]; /* command name, incl NUL */ vaddr_t ps_strings; /* User pointers to argv/env */ vaddr_t ps_timekeep; /* User pointer to timekeep */