]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
prefill/zimport: fix race condition on TA access
authorPetr Špaček <petr.spacek@nic.cz>
Fri, 24 Apr 2020 08:59:07 +0000 (10:59 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Fri, 24 Apr 2020 09:00:05 +0000 (11:00 +0200)
TA RRset might change asynchronously between zi_zone_import() and
zi_zone_process(), we cannot rely pointer from zi_zone_import().

daemon/zimport.c

index 73128eee8682cd05cae8999a4873ff7f43846d1c..84e3fd2f6c4a8f7dec35da867e93dfc06c66b7ee 100644 (file)
@@ -494,6 +494,15 @@ static void zi_zone_process(uv_timer_t* handle)
        }
        z_import->key = rr_key;
 
+       map_t *trust_anchors = &z_import->worker->engine->resolver.trust_anchors;
+       knot_rrset_t *rr_ta = kr_ta_get(trust_anchors, z_import->origin);
+       if (!rr_ta) {
+               kr_log_error("[zimport] error: TA vanished in middle of import");
+               failed = 1;
+               goto finish;
+       }
+       z_import->ta = rr_ta;
+
        VERBOSE_MSG(NULL, "started: zone: '%s'\n", zone_name_str);
 
        z_import->start_timestamp = kr_now();
@@ -770,9 +779,7 @@ int zi_zone_import(struct zone_import_ctx *z_import,
                        /* Try to find TA for worker->z_import.origin. */
                        map_t *trust_anchors = &z_import->worker->engine->resolver.trust_anchors;
                        knot_rrset_t *rr = kr_ta_get(trust_anchors, z_import->origin);
-                       if (rr) {
-                               z_import->ta = rr;
-                       } else {
+                       if (!rr) {
                                /* For now - fail.
                                 * TODO - query DS and continue after answer had been obtained. */
                                KR_DNAME_GET_STR(zone_name_str, z_import->origin);