summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp/ntp_intres.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2016-04-27 15:24:33 +0000
committerdelphij <delphij@FreeBSD.org>2016-04-27 15:24:33 +0000
commit392e7b947908b8f2f5662788d4243ccdfedad371 (patch)
tree83286d42b0265ff252ce801f09f05ec4ccf9e7e6 /contrib/ntp/libntp/ntp_intres.c
parent1df61c536d8a0f5edc0372de71d890814b9b277a (diff)
downloadFreeBSD-src-392e7b947908b8f2f5662788d4243ccdfedad371.zip
FreeBSD-src-392e7b947908b8f2f5662788d4243ccdfedad371.tar.gz
MFC r298695: MFV r298691: ntp 4.2.8p7.
Security: CVE-2016-1547, CVE-2016-1548, CVE-2016-1549, CVE-2016-1550 Security: CVE-2016-1551, CVE-2016-2516, CVE-2016-2517, CVE-2016-2518 Security: CVE-2016-2519 Security: FreeBSD-SA-16:16.ntp With hat: so
Diffstat (limited to 'contrib/ntp/libntp/ntp_intres.c')
-rw-r--r--contrib/ntp/libntp/ntp_intres.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/contrib/ntp/libntp/ntp_intres.c b/contrib/ntp/libntp/ntp_intres.c
index b0f5620..0b5bb75 100644
--- a/contrib/ntp/libntp/ntp_intres.c
+++ b/contrib/ntp/libntp/ntp_intres.c
@@ -201,8 +201,6 @@ static time_t next_res_init;
/* === forward declarations === */
static u_int reserve_dnschild_ctx(void);
static u_int get_dnschild_ctx(void);
-static void alloc_dnsworker_context(u_int);
-/* static void free_dnsworker_context(u_int); */
static dnsworker_ctx * get_worker_context(blocking_child *, u_int);
static void scheduled_sleep(time_t, time_t,
dnsworker_ctx *);
@@ -949,47 +947,41 @@ get_dnschild_ctx(void)
}
-static void
-alloc_dnsworker_context(
- u_int idx
- )
-{
- const size_t worker_context_sz = sizeof(*dnsworker_contexts[0]);
-
- REQUIRE(NULL == dnsworker_contexts[idx]);
- dnsworker_contexts[idx] = emalloc_zero(worker_context_sz);
-}
-
-
static dnsworker_ctx *
get_worker_context(
blocking_child * c,
u_int idx
)
{
- static size_t ps = sizeof(dnsworker_contexts[0]);
- u_int min_new_alloc;
- u_int new_alloc;
- size_t octets;
- size_t new_octets;
+ u_int min_new_alloc;
+ u_int new_alloc;
+ size_t octets;
+ size_t new_octets;
+ dnsworker_ctx * retv;
+ worker_global_lock(TRUE);
+
if (dnsworker_contexts_alloc <= idx) {
min_new_alloc = 1 + idx;
/* round new_alloc up to nearest multiple of 4 */
new_alloc = (min_new_alloc + 4) & ~(4 - 1);
- new_octets = new_alloc * ps;
- octets = dnsworker_contexts_alloc * ps;
+ new_octets = new_alloc * sizeof(dnsworker_ctx*);
+ octets = dnsworker_contexts_alloc * sizeof(dnsworker_ctx*);
dnsworker_contexts = erealloc_zero(dnsworker_contexts,
new_octets, octets);
dnsworker_contexts_alloc = new_alloc;
+ retv = emalloc_zero(sizeof(dnsworker_ctx));
+ dnsworker_contexts[idx] = retv;
+ } else if (NULL == (retv = dnsworker_contexts[idx])) {
+ retv = emalloc_zero(sizeof(dnsworker_ctx));
+ dnsworker_contexts[idx] = retv;
}
-
- if (NULL == dnsworker_contexts[idx])
- alloc_dnsworker_context(idx);
- ZERO(*dnsworker_contexts[idx]);
- dnsworker_contexts[idx]->c = c;
-
- return dnsworker_contexts[idx];
+
+ worker_global_lock(FALSE);
+
+ ZERO(*retv);
+ retv->c = c;
+ return retv;
}
OpenPOWER on IntegriCloud