From 8951901e8f77ae4804e12b6a9fb97e9d9f920502 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Mon, 27 Jul 2015 18:58:00 -0700 Subject: [PATCH] Handle exceptions during squid.conf parse Increasingly code used inside squid.conf parsing is capable of throwing exceptions to signal errors. Catch any unexpected exceptions that reach the config parse initiator(s) and report as a FATAL event before self destructing. Detected by Coverity Scan. Issue 1231352 --- src/main.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main.cc b/src/main.cc index ccf9dd4d82..9ca20c1796 100644 --- a/src/main.cc +++ b/src/main.cc @@ -851,10 +851,18 @@ mainReconfigureFinish(void *) // parse the config returns a count of errors encountered. const int oldWorkers = Config.workers; - if ( parseConfigFile(ConfigFile) != 0) { + try { + if (parseConfigFile(ConfigFile) != 0) { + // for now any errors are a fatal condition... + self_destruct(); + } + } catch (...) { // for now any errors are a fatal condition... + debugs(1, DBG_CRITICAL, "FATAL: Unhandled exception parsing config file. " << + " Run squid -k parse and check for errors."); self_destruct(); } + if (oldWorkers != Config.workers) { debugs(1, DBG_CRITICAL, "WARNING: Changing 'workers' (from " << oldWorkers << " to " << Config.workers << @@ -1462,7 +1470,14 @@ SquidMain(int argc, char **argv) Format::Token::Init(); // XXX: temporary. Use a runners registry of pre-parse runners instead. - parse_err = parseConfigFile(ConfigFile); + try { + parse_err = parseConfigFile(ConfigFile); + } catch (...) { + // for now any errors are a fatal condition... + debugs(1, DBG_CRITICAL, "FATAL: Unhandled exception parsing config file." << + (opt_parse_cfg_only ? " Run squid -k parse and check for errors." : "")); + parse_err = 1; + } Mem::Report(); -- 2.47.2