From: Amos Jeffries Date: Tue, 28 Jul 2015 01:58:00 +0000 (-0700) Subject: Handle exceptions during squid.conf parse X-Git-Tag: merge-candidate-3-v1~25^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8951901e8f77ae4804e12b6a9fb97e9d9f920502;p=thirdparty%2Fsquid.git 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 --- 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();