Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern don't use stack for name (requested by...



details:   https://anonhg.NetBSD.org/src/rev/67b994a56ca7
branches:  trunk
changeset: 318813:67b994a56ca7
user:      christos <christos%NetBSD.org@localhost>
date:      Sat May 05 22:14:45 2018 +0000
description:
don't use stack for name (requested by joerg)

diffstat:

 sys/kern/uipc_sem.c |  23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diffs (103 lines):

diff -r 1e8ebf3a76a4 -r 67b994a56ca7 sys/kern/uipc_sem.c
--- a/sys/kern/uipc_sem.c       Sat May 05 21:33:53 2018 +0000
+++ b/sys/kern/uipc_sem.c       Sat May 05 22:14:45 2018 +0000
@@ -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 @@
 #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 @@
 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 @@
                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 @@
        /* 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 @@
        fp->f_ksem = ks;
        fd_affix(p, fp, fd);
 err:
+       pathbuf_destroy(pb);
        if (error) {
                fd_abort(p, fp, fd);
        }
@@ -640,17 +647,21 @@
        /* {
                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;



Home | Main Index | Thread Index | Old Index