From 843419aa3f81f072cb0b921d258f26fd723f20ce Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Mon, 1 Feb 2010 12:20:22 +1300 Subject: [PATCH] Regression Fix: Make Squid abort on parse failures. 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 | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/main.cc b/src/main.cc index 9ec53c4d27..71cb6e232e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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); -- 2.47.2