From 2f00ad5ff05b7bc36cf6613544170558cca180c7 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sat, 10 Feb 2018 21:19:40 +0100 Subject: [PATCH] Error out if unknown properties are found in the config file And thanks to this, an inconsistency in the example config file vs the parser was found (`timeout` vs `timeout_ms`). Fixes #113 --- dnscrypt-proxy/config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index 23fdc19d..437d42c2 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -23,7 +23,7 @@ type Config struct { ListenAddresses []string `toml:"listen_addresses"` Daemonize bool ForceTCP bool `toml:"force_tcp"` - Timeout int `toml:"timeout_ms"` + Timeout int `toml:"timeout"` CertRefreshDelay int `toml:"cert_refresh_delay"` CertIgnoreTimestamp bool `toml:"cert_ignore_timestamp"` LBStrategy string `toml:"lb_strategy"` @@ -148,9 +148,14 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error { os.Exit(0) } config := newConfig() - if _, err := toml.DecodeFile(*configFile, &config); err != nil { + md, err := toml.DecodeFile(*configFile, &config) + if err != nil { return err } + undecoded := md.Undecoded() + if len(undecoded) > 0 { + return fmt.Errorf("Unsupported key in configuration file: [%s]", undecoded[0]) + } cdFileDir(*configFile) if config.LogLevel >= 0 && config.LogLevel < int(dlog.SeverityLast) { dlog.SetLogLevel(dlog.Severity(config.LogLevel))