From ad1ff0997e957cb2a8d1c05e0ed940ad5066a480 Mon Sep 17 00:00:00 2001 From: Robert Drehmel Date: Wed, 27 Feb 2002 16:43:20 +0000 Subject: [PATCH] Make getcredhostname() take a buffer and the buffer's size as arguments. The correct hostname is copied into the buffer while having the prison's lock acquired in a jailed process' case. Reviewed by: jhb, rwatson --- sys/kern/kern_jail.c | 15 ++++++++++++--- sys/sys/jail.h | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index 62d65fabc721..ac5b73266067 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -241,10 +241,19 @@ jailed(cred) /* * Return the correct hostname for the passed credential. */ -const char * -getcredhostname(cred) +void +getcredhostname(cred, buf, size) struct ucred *cred; + char *buf; + size_t size; { - return (jailed(cred) ? cred->cr_prison->pr_host : hostname); + if (jailed(cred)) { + mtx_lock(&cred->cr_prison->pr_mtx); + strncpy(buf, cred->cr_prison->pr_host, size); + mtx_unlock(&cred->cr_prison->pr_mtx); + } + else + strncpy(buf, hostname, size); + buf[size - 1] = '\0'; } diff --git a/sys/sys/jail.h b/sys/sys/jail.h index f9f7b814c133..1fef842a5f7d 100644 --- a/sys/sys/jail.h +++ b/sys/sys/jail.h @@ -68,7 +68,7 @@ extern int jail_sysvipc_allowed; struct ucred; struct sockaddr; int jailed __P((struct ucred *cred)); -const char *getcredhostname __P((struct ucred *cred)); +void getcredhostname __P((struct ucred *cred, char *, size_t)); int prison_check __P((struct ucred *cred1, struct ucred *cred2)); void prison_free __P((struct prison *pr)); u_int32_t prison_getip __P((struct ucred *cred));