rwrap: Remove name compression from URI RR
authorMatt Rogers <mrogers@redhat.com>
Tue, 23 Aug 2016 04:56:14 +0000 (00:56 -0400)
committerMichael Adam <obnox@samba.org>
Mon, 29 Aug 2016 06:32:17 +0000 (08:32 +0200)
Compression is wrong for URI records.

Signed-off-by: Matt Rogers <mrogers@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
src/resolv_wrapper.c
tests/test_dns_fake.c

index 455a0afefab081d4dfdf60324517701c91b902fd..7a3c9b7c4c7df90fd1c3e25069b8efa20423f994 100644 (file)
@@ -625,8 +625,7 @@ static ssize_t rwrap_fake_uri(struct rwrap_fake_rr *rr,
        uint8_t *a = answer;
        ssize_t resp_size;
        size_t rdata_size;
-       unsigned char uri_compressed[MAXDNAME];
-       ssize_t compressed_len;
+       size_t uri_len;
 
        if (rr->type != ns_t_uri) {
                RWRAP_LOG(RWRAP_LOG_ERROR, "Wrong type!\n");
@@ -634,15 +633,8 @@ static ssize_t rwrap_fake_uri(struct rwrap_fake_rr *rr,
        }
        RWRAP_LOG(RWRAP_LOG_TRACE, "Adding URI RR");
        rdata_size = 3 * sizeof(uint16_t);
-
-       /* Prepare the data to write */
-       compressed_len = ns_name_compress(rr->rrdata.uri_rec.uri,
-                                         uri_compressed, MAXDNAME,
-                                         NULL, NULL);
-       if (compressed_len < 0) {
-               return -1;
-       }
-       rdata_size += compressed_len;
+       uri_len = strlen(rr->rrdata.uri_rec.uri) + 1;
+       rdata_size += uri_len;
 
        resp_size = rwrap_fake_rdata_common(ns_t_uri, rdata_size,
                                            rr->key, anslen, &a);
@@ -652,7 +644,7 @@ static ssize_t rwrap_fake_uri(struct rwrap_fake_rr *rr,
 
        NS_PUT16(rr->rrdata.uri_rec.prio, a);
        NS_PUT16(rr->rrdata.uri_rec.weight, a);
-       memcpy(a, uri_compressed, compressed_len);
+       memcpy(a, rr->rrdata.uri_rec.uri, uri_len);
 
        return resp_size;
 }
index d3e9ebe6287cbaaa01ed8d9ff1dc575e912d81fc..348135cb239f0e03c883f0096911ce2e1d89edd4 100644 (file)
@@ -362,7 +362,6 @@ static void test_res_fake_uri_query(void **state)
        const uint8_t *rrdata;
        int prio;
        int weight;
-       char uri[MAXDNAME];
 
        (void) state; /* unused */
 
@@ -378,8 +377,8 @@ static void test_res_fake_uri_query(void **state)
 
        /*
         * The query must finish w/o an error, have one answer and the answer
-        * must be a parseable RR of type SRV and have the priority, weight,
-        * port and hostname as in the fake hosts file
+        * must be a parseable RR of type URI and have the priority, weight, and
+        * URI string as in the hosts file.
         */
        assert_int_equal(ns_msg_getflag(handle, ns_f_rcode), ns_r_noerror);
        assert_int_equal(ns_msg_count(handle, ns_s_an), 1);
@@ -390,15 +389,9 @@ static void test_res_fake_uri_query(void **state)
        NS_GET16(prio, rrdata);
        NS_GET16(weight, rrdata);
 
-       rv = ns_name_uncompress(ns_msg_base(handle),
-                               ns_msg_end(handle),
-                               rrdata,
-                               uri, MAXDNAME);
-       assert_int_not_equal(rv, -1);
-
        assert_int_equal(prio, 2);
        assert_int_equal(weight, 5);
-       assert_string_equal(uri, "https://vpn.cwrap.org/VPN");
+       assert_string_equal(rrdata, "https://vpn.cwrap.org/VPN");
 }
 
 /*
@@ -417,7 +410,6 @@ static void test_res_fake_uri_query_minimal(void **state)
        const uint8_t *rrdata;
        int prio;
        int weight;
-       char uri[MAXDNAME];
 
        (void) state; /* unused */
 
@@ -433,8 +425,8 @@ static void test_res_fake_uri_query_minimal(void **state)
 
        /*
         * The query must finish w/o an error, have one answer and the answer
-        * must be a parseable RR of type SRV and have the priority, weight,
-        * port and hostname as in the fake hosts file
+        * must be a parseable RR of type URI and have the priority, weight, and
+        * URI string as in the fake hosts file
         */
        assert_int_equal(ns_msg_getflag(handle, ns_f_rcode), ns_r_noerror);
        assert_int_equal(ns_msg_count(handle, ns_s_an), 1);
@@ -445,15 +437,9 @@ static void test_res_fake_uri_query_minimal(void **state)
        NS_GET16(prio, rrdata);
        NS_GET16(weight, rrdata);
 
-       rv = ns_name_uncompress(ns_msg_base(handle),
-                               ns_msg_end(handle),
-                               rrdata,
-                               uri, MAXDNAME);
-       assert_int_not_equal(rv, -1);
-
        assert_int_equal(prio, 1);
        assert_int_equal(weight, 100);
-       assert_string_equal(uri, "ftp://ftp.cwrap.org/public");
+       assert_string_equal(rrdata, "ftp://ftp.cwrap.org/public");
 }
 
 static void test_res_fake_soa_query(void **state)