]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix that malloc failure for new_local_rrset for RPZ qname
authorW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 17 Jun 2026 13:26:56 +0000 (15:26 +0200)
committerW.C.A. Wijngaards <wouter@nlnetlabs.nl>
Wed, 17 Jun 2026 13:26:56 +0000 (15:26 +0200)
  trigger RR insert does not crash. It does not link a
  partial RRset, and logs an error on failure, and cleans
  up the dname allocation. Thanks to Qifan Zhang, Palo Alto
  Networks, for the report.

doc/Changelog
services/localzone.c
services/rpz.c

index ce19e50a4d07d27313572a6b8c3442ae9d30e9a2..b3751dd5a147a4fbdd4725eef344f89f3ee8041b 100644 (file)
          not set up a half-built reply for cache store, that could
          lead to a crash. Thanks to Qifan Zhang, Palo Alto Networks,
          for the report.
+       - Fix that malloc failure for new_local_rrset for RPZ qname
+         trigger RR insert does not crash. It does not link a
+         partial RRset, and logs an error on failure, and cleans
+         up the dname allocation. Thanks to Qifan Zhang, Palo Alto
+         Networks, for the report.
 
 16 June 2026: Wouter
        - Fix to disallow $INCLUDE for secondary zones. Start up
index 7ad9376a93cf133fa9f6fdd32750b6b9f9a1acee..77fc5b6b907a97906823f1b85e9b5c52c8d5a626 100644 (file)
@@ -386,8 +386,6 @@ new_local_rrset(struct regional* region, struct local_data* node,
                log_err("out of memory");
                return NULL;
        }
-       rrset->next = node->rrsets;
-       node->rrsets = rrset;
        rrset->rrset = (struct ub_packed_rrset_key*)
                regional_alloc_zero(region, sizeof(*rrset->rrset));
        if(!rrset->rrset) {
@@ -408,6 +406,8 @@ new_local_rrset(struct regional* region, struct local_data* node,
        rrset->rrset->rk.dname_len = node->namelen;
        rrset->rrset->rk.type = htons(rrtype);
        rrset->rrset->rk.rrset_class = htons(rrclass);
+       rrset->next = node->rrsets;
+       node->rrsets = rrset;
        return rrset;
 }
 
index 46c23adf04bcad2fb0626ab6c3d33882451e4996..70bbeda563187b15357a814f4178b5a10e3ccba7 100644 (file)
@@ -721,13 +721,22 @@ rpz_insert_local_zones_trigger(struct local_zones* lz, uint8_t* dname,
                char* rrstr = sldns_wire2str_rr(rr, rr_len);
                if(rrstr == NULL) {
                        log_err("malloc error while inserting rpz nsdname trigger");
-                       free(dname);
+                       if(!newzone)
+                               free(dname);
                        lock_rw_unlock(&lz->lock);
                        return;
                }
                lock_rw_wrlock(&z->lock);
-               local_zone_enter_rr(z, dname, dnamelen, dnamelabs, rrtype,
-                                   rrclass, ttl, rdata, rdata_len, rrstr);
+               if(!local_zone_enter_rr(z, dname, dnamelen, dnamelabs, rrtype,
+                                   rrclass, ttl, rdata, rdata_len, rrstr)) {
+                       log_err("rpz: could not enter local-data: %s", rrstr);
+                       if(!newzone)
+                               free(dname);
+                       lock_rw_unlock(&z->lock);
+                       lock_rw_unlock(&lz->lock);
+                       free(rrstr);
+                       return;
+               }
                lock_rw_unlock(&z->lock);
                free(rrstr);
        }