]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix issues introduced by migration
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 17 Aug 2022 17:48:18 +0000 (18:48 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 17 Aug 2022 17:48:18 +0000 (18:48 +0100)
contrib/librdns/compression.c
contrib/librdns/packet.c
contrib/librdns/packet.h

index 7ee7d3d456dfb473be9b44173b60f0b7e58a94c3..895178eb10d927d97c8459517412d5cdbb087132 100644 (file)
@@ -37,6 +37,10 @@ rdns_can_compress (const char *pos, unsigned int len, khash_t(rdns_compression_h
        struct rdns_compression_name check;
        khiter_t k;
 
+       if (comp == NULL) {
+               return NULL;
+       }
+
        check.suffix_len = len;
        check.suffix = pos;
        k = kh_get(rdns_compression_hash, comp, check);
@@ -72,18 +76,21 @@ rdns_add_compressed (const char *pos, const char *end,
        struct rdns_compression_name new_name;
        int r;
 
-       assert (offset >= 0);
-       new_name.suffix_len = end - pos;
-       new_name.suffix = pos;
-       new_name.offset = offset;
+       if (comp != NULL) {
+
+               assert (offset >= 0);
+               new_name.suffix_len = end - pos;
+               new_name.suffix = pos;
+               new_name.offset = offset;
 
-       kh_put(rdns_compression_hash, comp, new_name, &r);
+               kh_put(rdns_compression_hash, comp, new_name, &r);
+       }
 }
 
 void
 rdns_compression_free (khash_t(rdns_compression_hash) *comp)
 {
-       if (comp) {
+       if (comp != NULL) {
                kh_destroy(rdns_compression_hash, comp);
        }
 }
@@ -102,24 +109,23 @@ rdns_write_name_compressed (struct rdns_request *req,
        if (comp != NULL && *comp == NULL) {
                *comp = kh_init(rdns_compression_hash);
        }
-       else if (comp == NULL) {
-               return false;
-       }
 
        while (pos < end && remain > 0) {
-               struct rdns_compression_name *test = rdns_can_compress (pos, end - pos, *comp);
-               if (test != NULL) {
-                       /* Can compress name */
-                       if (remain < 2) {
-                               rdns_info ("no buffer remain for constructing query");
-                               return false;
+               if (comp) {
+                       struct rdns_compression_name *test = rdns_can_compress(pos, end - pos, *comp);
+                       if (test != NULL) {
+                               /* Can compress name */
+                               if (remain < 2) {
+                                       rdns_info ("no buffer remain for constructing query");
+                                       return false;
+                               }
+
+                               pointer = htons ((uint16_t) test->offset) | DNS_COMPRESSION_BITS;
+                               memcpy(target, &pointer, sizeof(pointer));
+                               req->pos += 2;
+
+                               return true;
                        }
-
-                       pointer = htons ((uint16_t)test->offset) | DNS_COMPRESSION_BITS;
-                       memcpy (target, &pointer, sizeof (pointer));
-                       req->pos += 2;
-
-                       return true;
                }
 
                label_len = rdns_calculate_label_len (pos, end);
@@ -144,7 +150,9 @@ rdns_write_name_compressed (struct rdns_request *req,
                        label_len = remain - 1;
                }
 
-               rdns_add_compressed (pos, end, *comp, target - req->packet);
+               if (comp) {
+                       rdns_add_compressed(pos, end, *comp, target - req->packet);
+               }
                /* Write label as is */
                *target++ = (uint8_t)label_len;
                memcpy (target, pos, label_len);
index 5c822ffefc3b578b1e0f67a8ea93e46c78d3a30a..59a919e9f86a3834c9b9c79ddfb97b237df7ebe8 100644 (file)
@@ -245,7 +245,7 @@ err:
 
 bool
 rdns_add_rr (struct rdns_request *req, const char *name, unsigned int len,
-               enum dns_type type, struct rdns_compression_entry **comp)
+               enum dns_type type, struct kh_rdns_compression_hash_s **comp)
 {
        uint8_t *p8;
 
index 6d22de4e089839b8072a7d576349e457d76d0e22..44e16a50b4f2f012a3ff24793cccf9d4e144e98d 100644 (file)
@@ -27,7 +27,7 @@
 #include <stdint.h>
 #include "dns_private.h"
 
-struct rdns_compression_entry;
+struct kh_rdns_compression_hash_s;
 
 /**
  * Allocate dns packet suitable to handle up to `namelen` name
@@ -50,7 +50,7 @@ void rdns_make_dns_header (struct rdns_request *req, unsigned int qcount);
  * @param type type of resource record
  */
 bool rdns_add_rr (struct rdns_request *req, const char *name, unsigned int len,
-               enum dns_type type, struct rdns_compression_entry **comp);
+               enum dns_type type, struct kh_rdns_compression_hash_s **comp);
 
 /**
  * Add EDNS0 section