[PATCH] nsd-patch: fix segfault after renaming slave zone

Hi all,
we have discovered a segfault in nsd-patch when renaming slave zone in nsd
config file if some data for this zone still exists in the IXFR diff
database.
In my case, the zone "black" was renamed to "blackinwhite":

root@ggd115:/cage/nsd/var/nsd/zones#nsd-patch -c
/cage/nsd/etc/nsd-dns-slave.conf
reading database
reading updates to database
[1343043191] nsd-patch[10800]: error: xfr: zone black. not in config.
[1343043191] nsd-patch[10800]: error: no zone exists
writing changed zones
Segmentation fault (core dumped)

The problem is that on line 407 of nsd-patch it tries to printf() a
message "zone %s had not changed", where %s is zone->opts->name:

                for(zone = db->zones; zone; zone = zone->next)
                {
                        if(!force_write && !zone->updated) {
                                fprintf(stdout, "zone %s had not
changed.\n", zone->opts->name);
                                continue;
                        }

zone->opts is filled in in difffile.c around line 675:

zone->opts = zone_options_find(opt, domain_dname(zone->apex));
        if(!zone->opts) {
                log_msg(LOG_ERR, "xfr: zone %s not in config.",
                        dname_to_string(zone_name,0));
                return 0;
        }

As a result, nsd-patch tries to dereference a null pointer when trying to
print zone name.
I think the proper fix is to move the code that adds zone structure to the
linked list at the very end of find_zone(). Attached patch fixes the issue
described above. This patch is for nsd 3.2.11.

Please review and comment if you find it nessesary/useful/awful :slight_smile:

(attachments)

difffile.c.diff (826 Bytes)

Hi Ilya,

Thanks for your report. Considering your question:

Please review and comment if you find it nessesary/useful/awful
:slight_smile:

We think it is useful :slight_smile:

I have applied a similar fix in the NSD 3.2 branch (r3617). Instead of
moving down the code that adds the zone structure to the list, we
moved the lookup zone in options to above. This way, if the zone is
not in the options, we don't even have to allocate memory for it.

Best regards,
  Matthijs

Index: difffile.c

Hi Matthijs,
great, thanks for quick reply!
We have upgraded nsd and now use the latest 3.2.12 with this patch. If we
encounter any issues, will let you know.