]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Regression Fix: Make Squid abort on parse failures.
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 31 Jan 2010 23:20:22 +0000 (12:20 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 31 Jan 2010 23:20:22 +0000 (12:20 +1300)
The addition of multi-file parsing and catching of thrown errors between
them caused any errors in sub-files to be non-fatal and allow Squid to
run as if everything was normal, even if parts of the config were not
being loaded.

Squid will now propigate the error exception out and exit with a count of
the errors found.

The main() safety wrapper from 3.1 has also been ported to catch some
unwanted crashes.

src/main.cc

index 9ec53c4d27e6c5ee13446d03608edd35359412fa..71cb6e232ee31142ba5b62af06e69b5815911afb 100644 (file)
@@ -632,7 +632,11 @@ mainReconfigure(void)
     refererCloseLog();
     errorClean();
     enter_suid();              /* root to read config file */
-    parseConfigFile(ConfigFile, manager);
+    // parse the config returns a count of errors encountered.
+    if ( parseConfigFile(ConfigFile, manager) != 0) {
+        // for now any errors are a fatal condition...
+        self_destruct();
+    }
     setUmask(Config.umask);
     Mem::Report();
     setEffectiveUser();
@@ -1057,29 +1061,49 @@ mainInitialize(void)
     configured_once = 1;
 }
 
+// unsafe main routine -- may throw
+int SquidMain(int argc, char **argv);
+/// unsafe main routine wrapper to catch exceptions
+static int SquidMainSafe(int argc, char **argv);
+
 #if USE_WIN32_SERVICE
 /* When USE_WIN32_SERVICE is defined, the main function is placed in win32.cc */
 extern "C" void WINAPI
-    SquidWinSvcMain(int argc, char **argv)
+SquidWinSvcMain(int argc, char **argv)
 {
-    SquidMain(argc, argv);
+    SquidMainSafe(argc, argv);
 }
-
-int
-SquidMain(int argc, char **argv)
 #else
 int
 main(int argc, char **argv)
+{
+    return SquidMainSafe(argc, argv);
+}
 #endif
+
+static int
+SquidMainSafe(int argc, char **argv)
 {
-    int oldmask;
-#ifdef _SQUID_WIN32_
+    try {
+        return SquidMain(argc, argv);
+    } catch (const std::exception &e) {
+        std::cerr << "dying from an unhandled exception: " << e.what() << std::endl;
+        throw;
+    } catch (...) {
+        std::cerr << "dying from an unhandled exception." << std::endl;
+        throw;
+    }
+    return -1; // not reached
+}
 
+int
+SquidMain(int argc, char **argv)
+{
+#ifdef _SQUID_WIN32_
     int WIN32_init_err;
 #endif
 
 #if HAVE_SBRK
-
     sbrk_start = sbrk(0);
 #endif
 
@@ -1125,7 +1149,7 @@ main(int argc, char **argv)
      * set.  Unfortunately, there is no way to get the current
      * umask value without setting it.
      */
-    oldmask = umask(S_IRWXO);
+    int oldmask = umask(S_IRWXO);
 
     if (oldmask)
         umask(oldmask);
@@ -1210,9 +1234,7 @@ main(int argc, char **argv)
         parse_err = parseConfigFile(ConfigFile, manager);
 
         Mem::Report();
-        
-        if (opt_parse_cfg_only)
-
+        if (opt_parse_cfg_only || parse_err > 0)
             return parse_err;
     }
     setUmask(Config.umask);