]> granicus.if.org Git - libevent/commitdiff
Fix SEGFAULT after evdns_base_resume if no nameservers installed.
authorAzat Khuzhin <a3at.mail@gmail.com>
Fri, 10 May 2013 23:53:11 +0000 (03:53 +0400)
committerAzat Khuzhin <a3at.mail@gmail.com>
Mon, 13 May 2013 19:56:00 +0000 (19:56 +0000)
If there is no nameservers installed, using
evdns_base_nameserver_ip_add(), than evdns_base_resume() will SEGFAULT,
because of NULL dereference in evdns_requests_pump_waiting_queue()

evdns.c

diff --git a/evdns.c b/evdns.c
index 534da8370904034fbb4760d4afcdb8e4b37fedd2..7e667f8209e956008a0f9bd1129927ae7d7581bc 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -742,23 +742,31 @@ request_reissue(struct request *req) {
 
 /* this function looks for space on the inflight queue and promotes */
 /* requests from the waiting queue if it can. */
+/* */
+/* TODO: */
+/* add return code, see at nameserver_pick() and other functions. */
 static void
 evdns_requests_pump_waiting_queue(struct evdns_base *base) {
        ASSERT_LOCKED(base);
        while (base->global_requests_inflight < base->global_max_requests_inflight &&
                   base->global_requests_waiting) {
                struct request *req;
-               /* move a request from the waiting queue to the inflight queue */
+
                EVUTIL_ASSERT(base->req_waiting_head);
                req = base->req_waiting_head;
+
+               req->ns = nameserver_pick(base);
+               if (!req->ns)
+                       return;
+
+               /* move a request from the waiting queue to the inflight queue */
+               req->ns->requests_inflight++;
+
                evdns_request_remove(req, &base->req_waiting_head);
 
                base->global_requests_waiting--;
                base->global_requests_inflight++;
 
-               req->ns = nameserver_pick(base);
-               req->ns->requests_inflight++;
-
                request_trans_id_set(req, transaction_id_pick(base));
 
                evdns_request_insert(req, &REQ_HEAD(base, req->trans_id));
@@ -2468,6 +2476,7 @@ evdns_base_resume(struct evdns_base *base)
        EVDNS_LOCK(base);
        evdns_requests_pump_waiting_queue(base);
        EVDNS_UNLOCK(base);
+
        return 0;
 }