From b287e5714ba340295edd6d565a4175b2e70dafd2 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Tue, 11 Feb 2025 15:42:54 +0100 Subject: [PATCH] rec: document file extension of zone forward file and do not accept empty list of forwards The YAML code already disallows an empty forwarders list. The added case mainly covers the case when an old-style forward file is parsed as if it's YAML. This now generated an error: Feb 21 09:57:39 msg="Fatal error" error="empty list of forwarders for domain '- zone: example.com\"on line 1 of tmp/f.conf" subsystem="config" level="0" prio="Critical" tid="0" ts="1740128259.137" exception="PDNSException" This hopefully makes admins realize rec is trying to parse YAML content, but is expecting old-style as the file does not end in in .yml. --- pdns/recursordist/rec-rust-lib/table.py | 1 + pdns/recursordist/reczones.cc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/pdns/recursordist/rec-rust-lib/table.py b/pdns/recursordist/rec-rust-lib/table.py index e07e176a65..f38cf0ba0e 100644 --- a/pdns/recursordist/rec-rust-lib/table.py +++ b/pdns/recursordist/rec-rust-lib/table.py @@ -1140,6 +1140,7 @@ The DNSSEC notes from :ref:`setting-forward-zones` apply here as well. ''', 'doc-new' : ''' Same as :ref:`setting-forward-zones`, parsed from a file as a sequence of `Forward Zone`_. + The filename MUST end in ``.yml`` for the content to be parsed as YAML. .. code-block:: yaml diff --git a/pdns/recursordist/reczones.cc b/pdns/recursordist/reczones.cc index 0fee547035..6129f21aa0 100644 --- a/pdns/recursordist/reczones.cc +++ b/pdns/recursordist/reczones.cc @@ -65,6 +65,9 @@ static void convertServersForAD(const std::string& zone, const std::string& inpu { vector servers; stringtok(servers, input, sepa); + if (servers.empty()) { + throw PDNSException("empty list of forwarders for domain '" + zone + '"'); + } authDomain.d_servers.clear(); vector addresses; @@ -413,6 +416,9 @@ static void processForwardZonesFile(shared_ptr& newMap, sh try { convertServersForAD(domain, instructions, authDomain, ",; ", log, false); } + catch (const PDNSException& e) { + throw PDNSException(e.reason + "on line " + std::to_string(linenum) + " of " + filename); + } catch (...) { throw PDNSException("Conversion error parsing line " + std::to_string(linenum) + " of " + filename); } -- 2.47.2