summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroga <oga@openbsd.org>2009-06-12 14:56:21 +0000
committeroga <oga@openbsd.org>2009-06-12 14:56:21 +0000
commit7c3e900935b55c0973c43b72dd29c29dffcf59f1 (patch)
tree7372141384035c250556072faaf2a546a602f884
parentDocument new WRKOBJDIR default value. (diff)
downloadwireguard-openbsd-7c3e900935b55c0973c43b72dd29c29dffcf59f1.tar.xz
wireguard-openbsd-7c3e900935b55c0973c43b72dd29c29dffcf59f1.zip
rework pool_get() a bit so that if you call if with a constructor set
*and* PR_ZERO in flags, you will no longer zero our your nicely constructed object. Instead, now if you have a contructor set, and you set PR_ZERO, you will panic (it's invalid due to how constructor work). ok miod@ deraadt@ on earlier versions of the diff. ok tedu@ after he pointed out a couple of places I messed up. Problem initally noticed by ariane@ a while ago.
-rw-r--r--sys/kern/subr_pool.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c
index 0f155c0b12d..aa0d1213a81 100644
--- a/sys/kern/subr_pool.c
+++ b/sys/kern/subr_pool.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_pool.c,v 1.83 2009/06/04 18:48:54 deraadt Exp $ */
+/* $OpenBSD: subr_pool.c,v 1.84 2009/06/12 14:56:21 oga Exp $ */
/* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */
/*-
@@ -458,17 +458,24 @@ pool_get(struct pool *pp, int flags)
mtx_enter(&pp->pr_mtx);
v = pool_do_get(pp, flags);
mtx_leave(&pp->pr_mtx);
- if (v && pp->pr_ctor && pp->pr_ctor(pp->pr_arg, v, flags)) {
- mtx_enter(&pp->pr_mtx);
- pool_do_put(pp, v);
- mtx_leave(&pp->pr_mtx);
- v = NULL;
- }
- if (v) {
- pp->pr_nget++;
+ if (v == NULL)
+ return (v);
+
+ if (pp->pr_ctor) {
+ if (flags & PR_ZERO)
+ panic("pool_get: PR_ZERO when ctor set");
+ if (pp->pr_ctor(pp->pr_arg, v, flags)) {
+ mtx_enter(&pp->pr_mtx);
+ pool_do_put(pp, v);
+ mtx_leave(&pp->pr_mtx);
+ v = NULL;
+ }
+ } else {
if (flags & PR_ZERO)
memset(v, 0, pp->pr_size);
}
+ if (v != NULL)
+ pp->pr_nget++;
return (v);
}