Module Name: src Committed By: christos Date: Sat May 5 22:14:45 UTC 2018
Modified Files: src/sys/kern: uipc_sem.c Log Message: don't use stack for name (requested by joerg) To generate a diff of this commit: cvs rdiff -u -r1.49 -r1.50 src/sys/kern/uipc_sem.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/uipc_sem.c diff -u src/sys/kern/uipc_sem.c:1.49 src/sys/kern/uipc_sem.c:1.50 --- src/sys/kern/uipc_sem.c:1.49 Fri May 4 15:56:58 2018 +++ src/sys/kern/uipc_sem.c Sat May 5 18:14:45 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_sem.c,v 1.49 2018/05/04 19:56:58 christos Exp $ */ +/* $NetBSD: uipc_sem.c,v 1.50 2018/05/05 22:14:45 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.49 2018/05/04 19:56:58 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.50 2018/05/05 22:14:45 christos Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -72,6 +72,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v #include <sys/stat.h> #include <sys/kmem.h> #include <sys/fcntl.h> +#include <sys/namei.h> #include <sys/file.h> #include <sys/filedesc.h> #include <sys/kauth.h> @@ -445,19 +446,21 @@ int do_ksem_open(struct lwp *l, const char *semname, int oflag, mode_t mode, unsigned int value, intptr_t *idp, copyout_t docopyout) { - char name[SEM_MAX_NAMELEN + 1]; + const char *name; + struct pathbuf *pb; proc_t *p = l->l_proc; ksem_t *ksnew = NULL, *ks; file_t *fp; intptr_t id; int fd, error; - error = copyinstr(semname, name, sizeof(name), NULL); + error = pathbuf_copyin(semname, &pb); if (error) { return error; } error = fd_allocfile(&fp, &fd); if (error) { + pathbuf_destroy(pb); return error; } fp->f_type = DTYPE_SEM; @@ -474,10 +477,12 @@ do_ksem_open(struct lwp *l, const char * goto err; } + name = pathbuf_stringcopy_get(pb); if (oflag & O_CREAT) { /* Create a new semaphore. */ error = ksem_create(l, name, &ksnew, mode, value); if (error) { + pathbuf_stringcopy_put(pb, name); goto err; } KASSERT(ksnew != NULL); @@ -486,6 +491,7 @@ do_ksem_open(struct lwp *l, const char * /* Lookup for a semaphore with such name. */ mutex_enter(&ksem_lock); ks = ksem_lookup(name); + pathbuf_stringcopy_put(pb, name); if (ks) { KASSERT(mutex_owned(&ks->ks_lock)); mutex_exit(&ksem_lock); @@ -539,6 +545,7 @@ do_ksem_open(struct lwp *l, const char * fp->f_ksem = ks; fd_affix(p, fp, fd); err: + pathbuf_destroy(pb); if (error) { fd_abort(p, fp, fd); } @@ -640,17 +647,21 @@ sys__ksem_unlink(struct lwp *l, const st /* { const char *name; } */ - char name[SEM_MAX_NAMELEN + 1]; + const char *name; + struct pathbuf *pb; ksem_t *ks; u_int refcnt; int error; - error = copyinstr(SCARG(uap, name), name, sizeof(name), NULL); + error = pathbuf_copyin(SCARG(uap, name), &pb); if (error) return error; mutex_enter(&ksem_lock); + name = pathbuf_stringcopy_get(pb); ks = ksem_lookup(name); + pathbuf_stringcopy_put(pb, name); + pathbuf_destroy(pb); if (ks == NULL) { mutex_exit(&ksem_lock); return ENOENT;