From b73b5b27926772dae5388598f18eb1b12092c5c6 Mon Sep 17 00:00:00 2001 From: Sara Dickinson Date: Sun, 21 Jun 2015 16:55:12 +0100 Subject: [PATCH] Fix some bugs... --- src/context.c | 6 ++++-- src/request-internal.c | 8 ++------ src/stub.c | 20 ++++++++++++-------- src/test/getdns_query.c | 2 +- src/types-internal.h | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/context.c b/src/context.c index c8c7be81..28d115d8 100644 --- a/src/context.c +++ b/src/context.c @@ -79,15 +79,15 @@ getdns_upstream_transports[GETDNS_UPSTREAM_TRANSPORTS] = { static in_port_t getdns_port_array[GETDNS_UPSTREAM_TRANSPORTS] = { GETDNS_PORT_DNS, + GETDNS_PORT_DNS_OVER_TLS, GETDNS_PORT_DNS, - GETDNS_PORT_DNS_OVER_TLS }; char* getdns_port_str_array[] = { GETDNS_STR_PORT_DNS, + GETDNS_STR_PORT_DNS_OVER_TLS, GETDNS_STR_PORT_DNS, - GETDNS_STR_PORT_DNS_OVER_TLS }; /* Private functions */ @@ -937,6 +937,8 @@ getdns_context_destroy(struct getdns_context *context) if (context->namespaces) GETDNS_FREE(context->my_mf, context->namespaces); + if (context->dns_transports) + GETDNS_FREE(context->my_mf, context->dns_transports); if(context->fchg_resolvconf) { if(context->fchg_resolvconf->prevstat) diff --git a/src/request-internal.c b/src/request-internal.c index 90b343aa..33ef055c 100644 --- a/src/request-internal.c +++ b/src/request-internal.c @@ -62,7 +62,6 @@ network_req_cleanup(getdns_network_req *net_req) if (net_req->response && (net_req->response < net_req->wire_data || net_req->response > net_req->wire_data+ net_req->wire_data_sz)) GETDNS_FREE(net_req->owner->my_mf, net_req->response); - GETDNS_FREE(net_req->owner->my_mf, net_req->transports); } static int @@ -90,13 +89,10 @@ network_req_init(getdns_network_req *net_req, getdns_dns_req *owner, net_req->upstream = NULL; net_req->fd = -1; - net_req->transports = GETDNS_XMALLOC(net_req->owner->my_mf, - getdns_transport_list_t, - owner->context->dns_transport_count); - memcpy(owner->context->dns_transports, net_req->transports, - owner->context->dns_transport_count * sizeof(getdns_transport_list_t)); net_req->transport_count = owner->context->dns_transport_count; net_req->transport_current = 0; + memcpy(net_req->transports, owner->context->dns_transports, + net_req->transport_count * sizeof(getdns_transport_list_t)); memset(&net_req->event, 0, sizeof(net_req->event)); memset(&net_req->tcp, 0, sizeof(net_req->tcp)); net_req->query_id = 0; diff --git a/src/stub.c b/src/stub.c index ad913f19..21bb8639 100644 --- a/src/stub.c +++ b/src/stub.c @@ -556,6 +556,7 @@ upstream_idle_timeout_cb(void *userarg) if (upstream->tls_obj != NULL) { SSL_shutdown(upstream->tls_obj); SSL_free(upstream->tls_obj); + upstream->tls_obj = NULL; } close(fd); } @@ -1062,17 +1063,20 @@ stub_udp_read_cb(void *userarg) if (GLDNS_TC_WIRE(netreq->response)) { if (!(netreq->transport_current < netreq->transport_count)) goto done; - netreq->transport_current++; - if (netreq->transport_current != GETDNS_TRANSPORT_TCP) + getdns_transport_list_t next_transport = + netreq->transports[++netreq->transport_current]; + if (next_transport != GETDNS_TRANSPORT_TCP) goto done; - if ((netreq->fd = upstream_connect(upstream, netreq->transport_current, + /*TODO[TLS]: find fallback upstream generically*/ + if ((netreq->fd = upstream_connect(upstream, next_transport, dnsreq)) == -1) goto done; - + upstream_schedule_netreq(netreq->upstream, netreq); GETDNS_SCHEDULE_EVENT( - dnsreq->loop, netreq->fd, dnsreq->context->timeout, - getdns_eventloop_event_init(&netreq->event, netreq, - NULL, stub_tcp_write_cb, stub_timeout_cb)); + dnsreq->loop, netreq->upstream->fd, dnsreq->context->timeout, + getdns_eventloop_event_init(&netreq->event, netreq, NULL, + ( dnsreq->loop != netreq->upstream->loop /* Synchronous lookup? */ + ? netreq_upstream_write_cb : NULL), stub_timeout_cb)); return; } @@ -1631,7 +1635,7 @@ fallback_on_write(getdns_network_req *netreq) { DEBUG_STUB("%s\n", __FUNCTION__); /* TODO[TLS]: Fallback through all transports.*/ - if (netreq->transport_current = netreq->transport_count - 1) + if (netreq->transport_current == netreq->transport_count - 1) return STUB_TCP_ERROR; getdns_transport_list_t next_transport = diff --git a/src/test/getdns_query.c b/src/test/getdns_query.c index a390261e..5ce7631a 100644 --- a/src/test/getdns_query.c +++ b/src/test/getdns_query.c @@ -443,7 +443,7 @@ getdns_return_t parse_args(int argc, char **argv) return GETDNS_RETURN_GENERIC_ERROR; } size_t transport_count = 0; - getdns_transport_list_t transports[strlen(argv[])]; + getdns_transport_list_t transports[GETDNS_TRANSPORTS_MAX]; if ((r = fill_transport_list(context, argv[i], transports, &transport_count)) || (r = getdns_context_set_dns_transport_list(context, transport_count, transports))){ diff --git a/src/types-internal.h b/src/types-internal.h index fb6af68e..51a83c72 100644 --- a/src/types-internal.h +++ b/src/types-internal.h @@ -206,7 +206,7 @@ typedef struct getdns_network_req /* For stub resolving */ struct getdns_upstream *upstream; int fd; - getdns_transport_list_t *transports; + getdns_transport_list_t transports[GETDNS_TRANSPORTS_MAX]; size_t transport_count; size_t transport_current; getdns_eventloop_event event;