From 6e8628f796fd750049dae67b9aba8506f3501402 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 12 May 2021 17:43:13 +0200 Subject: [PATCH] Print an error if a block/allow rule contains more than a pattern ... and it is not a time range. --- dnscrypt-proxy/plugin_allow_name.go | 10 +++++++--- dnscrypt-proxy/plugin_block_name.go | 12 ++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/dnscrypt-proxy/plugin_allow_name.go b/dnscrypt-proxy/plugin_allow_name.go index 005cbbc8..f0095d07 100644 --- a/dnscrypt-proxy/plugin_allow_name.go +++ b/dnscrypt-proxy/plugin_allow_name.go @@ -43,10 +43,14 @@ func (plugin *PluginAllowName) Init(proxy *Proxy) error { parts := strings.Split(line, "@") timeRangeName := "" if len(parts) == 2 { - line = strings.TrimSpace(parts[0]) - timeRangeName = strings.TrimSpace(parts[1]) + if timeRangeParts := strings.Split(parts[1], "@"); len(timeRangeParts) == 2 { + timeRangeName = strings.TrimSpace(timeRangeParts[1]) + } else { + dlog.Errorf("Syntax error in allowed names at line %d", 1+lineNo) + continue + } } else if len(parts) > 2 { - dlog.Errorf("Syntax error in allowed names at line %d -- Unexpected @ character", 1+lineNo) + dlog.Errorf("Syntax error in allowed names at line %d", 1+lineNo) continue } var weeklyRanges *WeeklyRanges diff --git a/dnscrypt-proxy/plugin_block_name.go b/dnscrypt-proxy/plugin_block_name.go index ae16be62..118406f2 100644 --- a/dnscrypt-proxy/plugin_block_name.go +++ b/dnscrypt-proxy/plugin_block_name.go @@ -97,13 +97,17 @@ func (plugin *PluginBlockName) Init(proxy *Proxy) error { if len(line) == 0 { continue } - parts := strings.Split(line, "@") + parts := strings.Fields(line) timeRangeName := "" if len(parts) == 2 { - line = strings.TrimSpace(parts[0]) - timeRangeName = strings.TrimSpace(parts[1]) + if timeRangeParts := strings.Split(parts[1], "@"); len(timeRangeParts) == 2 { + timeRangeName = strings.TrimSpace(timeRangeParts[1]) + } else { + dlog.Errorf("Syntax error in block rules at line %d", 1+lineNo) + continue + } } else if len(parts) > 2 { - dlog.Errorf("Syntax error in block rules at line %d -- Unexpected @ character", 1+lineNo) + dlog.Errorf("Syntax error in block rules at line %d", 1+lineNo) continue } var weeklyRanges *WeeklyRanges