mirror of
https://github.com/openbsd/src.git
synced 2026-06-18 15:23:33 +02:00
Use temporary buffer for thread name copying between kernel space and
user land within sys_{get,set}thrname().
ok claudio
This commit is contained in:
+13
-11
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: kern_prot.c,v 1.84 2025/12/03 17:05:53 kurt Exp $ */
|
||||
/* $OpenBSD: kern_prot.c,v 1.85 2026/06/10 04:45:22 mvs Exp $ */
|
||||
/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */
|
||||
|
||||
/*
|
||||
@@ -1122,6 +1122,7 @@ sys_getthrname(struct proc *curp, void *v, register_t *retval)
|
||||
syscallarg(size_t) len;
|
||||
} */ *uap = v;
|
||||
struct proc *p;
|
||||
char buf[sizeof(p->p_name)];
|
||||
size_t len;
|
||||
int tid = SCARG(uap, tid);
|
||||
int error;
|
||||
@@ -1129,11 +1130,12 @@ sys_getthrname(struct proc *curp, void *v, register_t *retval)
|
||||
p = tid ? tfind_user(tid, curp->p_p) : curp;
|
||||
if (p == NULL)
|
||||
return ESRCH;
|
||||
strlcpy(buf, p->p_name, sizeof(buf));
|
||||
|
||||
len = SCARG(uap, len);
|
||||
if (len > sizeof(p->p_name))
|
||||
len = sizeof(p->p_name);
|
||||
error = copyoutstr(p->p_name, SCARG(uap, name), len, NULL);
|
||||
if (len > sizeof(buf))
|
||||
len = sizeof(buf);
|
||||
error = copyoutstr(buf, SCARG(uap, name), len, NULL);
|
||||
if (error == ENAMETOOLONG)
|
||||
error = ERANGE;
|
||||
*retval = error;
|
||||
@@ -1148,21 +1150,21 @@ sys_setthrname(struct proc *curp, void *v, register_t *retval)
|
||||
syscallarg(const char *) name;
|
||||
} */ *uap = v;
|
||||
struct proc *p;
|
||||
char buf[sizeof p->p_name];
|
||||
char buf[sizeof(p->p_name)];
|
||||
int tid = SCARG(uap, tid);
|
||||
int error;
|
||||
|
||||
p = tid ? tfind_user(tid, curp->p_p) : curp;
|
||||
if (p == NULL)
|
||||
return ESRCH;
|
||||
|
||||
error = copyinstr(SCARG(uap, name), buf, sizeof buf, NULL);
|
||||
error = copyinstr(SCARG(uap, name), buf, sizeof(buf), NULL);
|
||||
if (error == ENAMETOOLONG) {
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
error = 0;
|
||||
}
|
||||
if (error == 0)
|
||||
if (error == 0) {
|
||||
p = tid ? tfind_user(tid, curp->p_p) : curp;
|
||||
if (p == NULL)
|
||||
return ESRCH;
|
||||
strlcpy(p->p_name, buf, sizeof(p->p_name));
|
||||
}
|
||||
*retval = error;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user