]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4612. [bug] Silence 'may be use uninitalised' warning and simplify
authorMark Andrews <marka@isc.org>
Mon, 1 May 2017 23:23:49 +0000 (09:23 +1000)
committerMark Andrews <marka@isc.org>
Mon, 1 May 2017 23:23:49 +0000 (09:23 +1000)
                        the code in lwres/getaddinfo:process_answer.
                        [RT #45158]

CHANGES
lib/irs/getaddrinfo.c

diff --git a/CHANGES b/CHANGES
index acaf41e29c08647a4babe1e7014622ce54992b9a..0196f3d53049714e1b41ea7ad75c3193b1f46d8c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+4612.  [bug]           Silence 'may be use uninitalised' warning and simplify
+                       the code in lwres/getaddinfo:process_answer.
+                       [RT #45158]
+
 4611.  [bug]           The default LMDB mapsize was too low and caused
                        errors after few thousand zones were added using
                        rndc addzone. A new config option "lmdb-mapsize"
index c41be9fbe6c630dc996e94ad654d4400c6f7c197..b15830d20b55fbb1b2fd8e14e6736c93b626119f 100644 (file)
@@ -681,6 +681,7 @@ process_answer(isc_task_t *task, isc_event_t *event) {
        dns_clientresevent_t *rev = (dns_clientresevent_t *)event;
        dns_rdatatype_t qtype;
        dns_name_t *name;
+       isc_boolean_t wantcname;
 
        REQUIRE(trans != NULL);
        resstate = trans->resstate;
@@ -724,14 +725,26 @@ process_answer(isc_task_t *task, isc_event_t *event) {
                goto done;
        }
 
+       wantcname = ISC_TF((resstate->head->ai_flags & AI_CANONNAME) != 0);
+
        /* Parse the response and construct the addrinfo chain */
        for (name = ISC_LIST_HEAD(rev->answerlist); name != NULL;
             name = ISC_LIST_NEXT(name, link)) {
                isc_result_t result;
                dns_rdataset_t *rdataset;
-               isc_buffer_t b;
-               isc_region_t r;
-               char t[1024];
+               char cname[1024];
+
+               if (wantcname) {
+                       isc_buffer_t b;
+
+                       isc_buffer_init(&b, cname, sizeof(cname));
+                       result = dns_name_totext(name, ISC_TRUE, &b);
+                       if (result != ISC_R_SUCCESS) {
+                               error = EAI_FAIL;
+                               goto done;
+                       }
+                       isc_buffer_putuint8(&b, '\0');
+               }
 
                for (rdataset = ISC_LIST_HEAD(name->list);
                     rdataset != NULL;
@@ -741,17 +754,6 @@ process_answer(isc_task_t *task, isc_event_t *event) {
                        if (rdataset->type != qtype)
                                continue;
 
-                       if ((resstate->head->ai_flags & AI_CANONNAME) != 0) {
-                               isc_buffer_init(&b, t, sizeof(t));
-                               result = dns_name_totext(name, ISC_TRUE, &b);
-                               if (result != ISC_R_SUCCESS) {
-                                       error = EAI_FAIL;
-                                       goto done;
-                               }
-                               isc_buffer_putuint8(&b, '\0');
-                               isc_buffer_usedregion(&b, &r);
-                       }
-
                        for (result = dns_rdataset_first(rdataset);
                             result == ISC_R_SUCCESS;
                             result = dns_rdataset_next(rdataset)) {
@@ -780,7 +782,8 @@ process_answer(isc_task_t *task, isc_event_t *event) {
                                switch (family) {
                                case AF_INET:
                                        dns_rdataset_current(rdataset, &rdata);
-                                       result = dns_rdata_tostruct(&rdata, &rdata_a,
+                                       result = dns_rdata_tostruct(&rdata,
+                                                                   &rdata_a,
                                                                    NULL);
                                        RUNTIME_CHECK(result == ISC_R_SUCCESS);
                                        SIN(ai->ai_addr)->sin_port =
@@ -791,7 +794,8 @@ process_answer(isc_task_t *task, isc_event_t *event) {
                                        break;
                                case AF_INET6:
                                        dns_rdataset_current(rdataset, &rdata);
-                                       result = dns_rdata_tostruct(&rdata, &rdata_aaaa,
+                                       result = dns_rdata_tostruct(&rdata,
+                                                                   &rdata_aaaa,
                                                                    NULL);
                                        RUNTIME_CHECK(result == ISC_R_SUCCESS);
                                        SIN6(ai->ai_addr)->sin6_port =
@@ -802,10 +806,8 @@ process_answer(isc_task_t *task, isc_event_t *event) {
                                        break;
                                }
 
-                               if ((resstate->head->ai_flags & AI_CANONNAME)
-                                   != 0) {
-                                       ai->ai_canonname =
-                                               strdup((const char *)r.base);
+                               if (wantcname) {
+                                       ai->ai_canonname = strdup(cname);
                                        if (ai->ai_canonname == NULL) {
                                                error = EAI_MEMORY;
                                                goto done;