Module Name: src Committed By: christos Date: Tue Nov 7 15:57:38 UTC 2017
Modified Files: src/sys/kern: vfs_syscalls.c Log Message: We computed the length of the string already, so use it... To generate a diff of this commit: cvs rdiff -u -r1.516 -r1.517 src/sys/kern/vfs_syscalls.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/vfs_syscalls.c diff -u src/sys/kern/vfs_syscalls.c:1.516 src/sys/kern/vfs_syscalls.c:1.517 --- src/sys/kern/vfs_syscalls.c:1.516 Wed May 31 22:45:13 2017 +++ src/sys/kern/vfs_syscalls.c Tue Nov 7 10:57:38 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.516 2017/06/01 02:45:13 chs Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.517 2017/11/07 15:57:38 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.516 2017/06/01 02:45:13 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.517 2017/11/07 15:57:38 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_fileassoc.h" @@ -2466,6 +2466,7 @@ do_sys_symlinkat(struct lwp *l, const ch struct vattr vattr; char *path; int error; + size_t len; struct pathbuf *linkpb; struct nameidata nd; @@ -2473,20 +2474,21 @@ do_sys_symlinkat(struct lwp *l, const ch path = PNBUF_GET(); if (seg == UIO_USERSPACE) { - if ((error = copyinstr(patharg, path, MAXPATHLEN, NULL)) != 0) + if ((error = copyinstr(patharg, path, MAXPATHLEN, &len)) != 0) goto out1; if ((error = pathbuf_copyin(link, &linkpb)) != 0) goto out1; } else { - KASSERT(strlen(patharg) < MAXPATHLEN); - strcpy(path, patharg); + len = strlen(patharg) + 1; + KASSERT(len <= MAXPATHLEN); + memcpy(path, patharg, len); linkpb = pathbuf_create(link); if (linkpb == NULL) { error = ENOMEM; goto out1; } } - ktrkuser("symlink-target", path, strlen(path)); + ktrkuser("symlink-target", path, len - 1); NDINIT(&nd, CREATE, LOCKPARENT | TRYEMULROOT, linkpb); if ((error = fd_nameiat(l, fdat, &nd)) != 0)