DF-0939 / fix.diff
--- a/sys/vfs/procfs/procfs_type.c +++ b/sys/vfs/procfs/procfs_type.c @@ -48,19 +48,25 @@ int procfs_dotype(struct proc *curp, struct lwp *lp, struct pfsnode *pfs, struct uio *uio) { struct proc *p = lp->lwp_proc; + const char *emul; int len; int error; /* * buffer for emulation type */ char mebuffer[256]; char *none = "Not Available"; + emul = (p != NULL && p->p_sysent != NULL && + p->p_sysent->sv_name != NULL) ? p->p_sysent->sv_name : none; + if (uio->uio_rw != UIO_READ) return (EOPNOTSUPP); if (uio->uio_offset != 0) return (0); - if (p && p->p_sysent && p->p_sysent->sv_name) { - len = strlen(p->p_sysent->sv_name); - bcopy(p->p_sysent->sv_name, mebuffer, len); - } else { - len = strlen(none); - bcopy(none, mebuffer, len); - } + /* + * sv_name is typically a short literal, but the sysentvec API + * imposes no length limit; bound the copy to leave room for the + * trailing newline so a long name cannot overflow the stack. + */ + len = strnlen(emul, sizeof(mebuffer) - 1); + bcopy(emul, mebuffer, len); mebuffer[len++] = '\n'; error = uiomove(mebuffer, len, uio); return error; } |