mirror of
https://github.com/openbsd/src.git
synced 2025-12-06 07:58:21 +00:00
Instead of failing with EINVAL when setthrname(2) is passed a thread
name longer then _MAXCOMLEN-1, truncate the name to fit. This is likely what the user wants and saves them from having to snprintf(3) into a buffer sized _MAXCOMLEN first. Man page update to follow. This makes pthread_set_name_np(3) succeed with long thread names instead of silently failing. ok deraadt@ miod@ sthen@ mpi@
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: kern_prot.c,v 1.83 2024/10/08 09:05:40 claudio Exp $ */
|
/* $OpenBSD: kern_prot.c,v 1.84 2025/12/03 17:05:53 kurt Exp $ */
|
||||||
/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */
|
/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1157,10 +1157,12 @@ sys_setthrname(struct proc *curp, void *v, register_t *retval)
|
|||||||
return ESRCH;
|
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)
|
||||||
strlcpy(p->p_name, buf, sizeof(p->p_name));
|
strlcpy(p->p_name, buf, sizeof(p->p_name));
|
||||||
else if (error == ENAMETOOLONG)
|
|
||||||
error = EINVAL;
|
|
||||||
*retval = error;
|
*retval = error;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user