]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Handle exceptions during squid.conf parse
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 29 Jul 2015 08:56:44 +0000 (01:56 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 29 Jul 2015 08:56:44 +0000 (01:56 -0700)
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

index 281dd93bb06c229292ffff79eec84170cf46c25b..d8885adc75fa30e87218d6596a358042f7988e94 100644 (file)
@@ -781,10 +781,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 <<
@@ -1393,7 +1401,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();