From 43ab646af96f6de5ba820a38c0c5c5f5ff5ba7dc Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Mon, 18 Jan 2016 13:50:43 +0100 Subject: [PATCH] Validate configured LogLevel when reading-in the config file. Signed-off-by: Stefan Schantl --- modules/Config.pm | 8 +++++++- modules/Logger.pm | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/Config.pm b/modules/Config.pm index 569b2ce..038ba35 100644 --- a/modules/Config.pm +++ b/modules/Config.pm @@ -153,7 +153,13 @@ sub CheckConfig (\%) { } } - # XXX - add check for validating the configured loglevel. + # Gather details about supported log levels. + my %supported_loglevels = &Guardian::Logger::GetLogLevels(); + + # Check if the configured log level is valid. + unless (exists ($supported_loglevels{$config{LogLevel}})) { + return "Invalid LogLevel: $config{LogLevel}"; + } # The config looks good, so return nothing (no error message). return undef diff --git a/modules/Logger.pm b/modules/Logger.pm index 270a059..dbd3a81 100644 --- a/modules/Logger.pm +++ b/modules/Logger.pm @@ -91,7 +91,7 @@ sub Log ($$) { ## This really simple function just returns the hash which ## contains all supported log levels. # -sub LogLevels () { +sub GetLogLevels () { # Nothing to do, just return the loglevels hash. return %loglevels; } -- 2.39.5