diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2019-12-13 14:37:04 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2019-12-13 14:37:04 +0000 |
commit | 8065cb23e31e2ad83eeada28a2c7c94e93385025 (patch) | |
tree | 5f6fef3545700d3e91fbcd422f784c9dc5cb0759 | |
parent | 9295e94bc8a351788ad0546340edb924333c9781 (diff) |
Avoid leaks by using the _buf versions of sldns_wire2str_* functions.
Also add some consistentcy checking to detect logic errors. ok @florian
-rw-r--r-- | sbin/unwind/Makefile | 4 | ||||
-rw-r--r-- | sbin/unwind/frontend.c | 19 | ||||
-rw-r--r-- | sbin/unwind/libunbound/util/alloc.c | 2 | ||||
-rw-r--r-- | sbin/unwind/resolver.c | 16 |
4 files changed, 29 insertions, 12 deletions
diff --git a/sbin/unwind/Makefile b/sbin/unwind/Makefile index cac03af8556..87252ffce30 100644 --- a/sbin/unwind/Makefile +++ b/sbin/unwind/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.5 2019/11/27 17:09:12 florian Exp $ +# $OpenBSD: Makefile,v 1.6 2019/12/13 14:37:03 otto Exp $ PROG= unwind SRCS= control.c resolver.c frontend.c log.c unwind.c parse.y printconf.c @@ -6,7 +6,7 @@ MAN= unwind.8 unwind.conf.5 .include "${.CURDIR}/libunbound/Makefile.inc" -#DEBUG= -g -DDEBUG=3 -O0 +DEBUG= -g -DDEBUG=3 -O0 CFLAGS+= -Wall -I${.CURDIR} -I ${.CURDIR}/libunbound/libunbound CFLAGS+= -I ${.CURDIR}/libunbound CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes diff --git a/sbin/unwind/frontend.c b/sbin/unwind/frontend.c index a44c1849c5e..b1792efb668 100644 --- a/sbin/unwind/frontend.c +++ b/sbin/unwind/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.47 2019/12/11 15:50:47 otto Exp $ */ +/* $OpenBSD: frontend.c,v 1.48 2019/12/13 14:37:03 otto Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -192,6 +192,8 @@ frontend(int debug, int verbose) signal(SIGHUP, SIG_IGN); /* Setup pipe and event handler to the parent process. */ + if (iev_main != NULL) + fatal("iev_main"); if ((iev_main = malloc(sizeof(struct imsgev))) == NULL) fatal(NULL); imsg_init(&iev_main->ibuf, 3); @@ -307,6 +309,8 @@ frontend_dispatch_main(int fd, short event, void *bula) break; } + if (iev_resolver != NULL) + fatal("iev_resolver"); iev_resolver = malloc(sizeof(struct imsgev)); if (iev_resolver == NULL) fatal(NULL); @@ -467,6 +471,8 @@ frontend_dispatch_resolver(int fd, short event, void *bula) if (pq == NULL) fatalx("IMSG_ANSWER without HEADER"); + if (pq->answer) + fatal("pq->answer"); if ((pq->answer = malloc(IMSG_DATA_SIZE(imsg))) != NULL) { pq->answer_len = IMSG_DATA_SIZE(imsg); @@ -541,6 +547,8 @@ udp_receive(int fd, short events, void *arg) int ret; char *str; char dname[LDNS_MAX_DOMAINLEN + 1]; + char qclass_buf[16]; + char qtype_buf[16]; memset(&qinfo, 0, sizeof(qinfo)); @@ -583,7 +591,7 @@ udp_receive(int fd, short events, void *arg) goto drop; else pq->rcode_override = ret; - goto send_answer; + goto send_answer; } if (!query_info_parse(&qinfo, pq->qbuf)) { @@ -597,9 +605,10 @@ udp_receive(int fd, short events, void *arg) } dname_str(qinfo.qname, dname); + sldns_wire2str_class_buf(qinfo.qclass, qclass_buf, sizeof(qclass_buf)); + sldns_wire2str_type_buf(qinfo.qtype, qtype_buf, sizeof(qtype_buf)); log_debug("%s: %s %s %s ?", ip_port((struct sockaddr *)&udpev->from), - dname, sldns_wire2str_class(qinfo.qclass), - sldns_wire2str_type(qinfo.qtype)); + dname, qclass_buf, qtype_buf); find.domain = dname; if (RB_FIND(bl_tree, &bl_head, &find) != NULL) { @@ -673,6 +682,8 @@ chaos_answer(struct pending_query *pq) len = strlen(name); size = sldns_buffer_capacity(pq->qbuf) + COMPRESSED_RR_SIZE + 1 + len; + if (pq->answer != 0) + fatal("chaos_answer"); if ((pq->answer = calloc(1, size)) == NULL) return; pq->answer_len = size; diff --git a/sbin/unwind/libunbound/util/alloc.c b/sbin/unwind/libunbound/util/alloc.c index 7e9618931ca..e9613b10dcd 100644 --- a/sbin/unwind/libunbound/util/alloc.c +++ b/sbin/unwind/libunbound/util/alloc.c @@ -113,7 +113,7 @@ alloc_init(struct alloc_cache* alloc, struct alloc_cache* super, alloc->last_id -= 1; /* for compiler portability. */ alloc->last_id |= alloc->next_id; alloc->next_id += 1; /* because id=0 is special. */ - alloc->max_reg_blocks = 100; + alloc->max_reg_blocks = 10; alloc->num_reg_blocks = 0; alloc->reg_list = NULL; alloc->cleanup = NULL; diff --git a/sbin/unwind/resolver.c b/sbin/unwind/resolver.c index f006ac8d401..8d566fa8f57 100644 --- a/sbin/unwind/resolver.c +++ b/sbin/unwind/resolver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resolver.c,v 1.107 2019/12/12 09:28:58 florian Exp $ */ +/* $OpenBSD: resolver.c,v 1.108 2019/12/13 14:37:03 otto Exp $ */ /* * Copyright (c) 2018 Florian Obser <florian@openbsd.org> @@ -754,6 +754,8 @@ try_next_resolver(struct running_query *rq) struct timespec tp, elapsed; struct timeval tv = {0, 0}; int64_t ms; + char qclass_buf[16]; + char qtype_buf[16]; while(rq->next_resolver < rq->res_pref.len && (res=resolvers[rq->res_pref.types[rq->next_resolver]]) == NULL) @@ -771,10 +773,11 @@ try_next_resolver(struct running_query *rq) timespecsub(&tp, &rq->tp, &elapsed); ms = elapsed.tv_sec * 1000 + elapsed.tv_nsec / 1000000; + sldns_wire2str_class_buf(rq->query_imsg->c, qclass_buf, sizeof(qclass_buf)); + sldns_wire2str_type_buf(rq->query_imsg->t, qtype_buf, sizeof(qtype_buf)); log_debug("%s[+%lldms]: %s[%s] %s %s %s", __func__, ms, uw_resolver_type_str[res->type], uw_resolver_state_str[res->state], - rq->query_imsg->qname, sldns_wire2str_class(rq->query_imsg->c), - sldns_wire2str_type(rq->query_imsg->t)); + rq->query_imsg->qname, qclass_buf, qtype_buf); if ((query_imsg = malloc(sizeof(*query_imsg))) == NULL) { log_warnx("%s", __func__); @@ -887,6 +890,8 @@ resolve_done(struct uw_resolver *res, void *arg, int rcode, int r, asr_pref_pos = -1, force_acceptbogus = 0; char *str; char rcode_buf[16]; + char qclass_buf[16]; + char qtype_buf[16]; clock_gettime(CLOCK_MONOTONIC, &tp); @@ -939,10 +944,11 @@ resolve_done(struct uw_resolver *res, void *arg, int rcode, result->answer_len = 0; sldns_wire2str_rcode_buf(result->rcode, rcode_buf, sizeof(rcode_buf)); + sldns_wire2str_class_buf(query_imsg->c, qclass_buf, sizeof(qclass_buf)); + sldns_wire2str_rcode_buf(query_imsg->t, qtype_buf, sizeof(qtype_buf)); log_debug("%s[%s]: %s %s %s rcode: %s[%d], elapsed: %lldms, running: %d", __func__, uw_resolver_type_str[res->type], query_imsg->qname, - sldns_wire2str_class(query_imsg->c), - sldns_wire2str_type(query_imsg->t), rcode_buf, result->rcode, ms, + qclass_buf, qtype_buf, rcode_buf, result->rcode, ms, running_query_cnt()); force_acceptbogus = find_force(&resolver_conf->force, query_imsg->qname, |