------------------------------------------------------------ revno: 13872 revision-id: squid3@treenet.co.nz-20150729085644-girwhhhem6isll26 parent: squid3@treenet.co.nz-20150729085408-lb6vrrd11nwg2p6a committer: Amos Jeffries branch nick: 3.5 timestamp: Wed 2015-07-29 01:56:44 -0700 message: 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 ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20150729085644-girwhhhem6isll26 # target_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # testament_sha1: 4709fc657b208c281978e143001d1c19b8de67c3 # timestamp: 2015-07-29 08:58:38 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/3.5 # base_revision_id: squid3@treenet.co.nz-20150729085408-\ # lb6vrrd11nwg2p6a # # Begin patch === modified file 'src/main.cc' --- src/main.cc 2015-07-24 13:30:14 +0000 +++ src/main.cc 2015-07-29 08:56:44 +0000 @@ -781,10 +781,18 @@ // 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 << @@ -1393,7 +1401,14 @@ 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();