From 65ae31c658000440d68c670ed6362fa8f2ce2c1c Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Fri, 6 Feb 2015 12:09:03 -0800 Subject: [PATCH] Fix crash when parsing invalid squid.conf If a time value is going to overflow with default units the critical debugs() can trigger a segfault instead of logging and aborting Squid with self_destruct(). Detected by Coverity Scan. Issue 1258698 --- src/cache_cf.cc | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 92fc0a0deb..1b2cb52364 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -984,43 +984,37 @@ parse_obsolete(const char *name) static void parseTimeLine(time_msec_t * tptr, const char *units, bool allowMsec, bool expectMoreArguments = false) { - char *token; - double d; - time_msec_t m; time_msec_t u; - if ((u = parseTimeUnits(units, allowMsec)) == 0) self_destruct(); + char *token; if ((token = ConfigParser::NextToken()) == NULL) self_destruct(); - d = xatof(token); + double d = xatof(token); - m = u; /* default to 'units' if none specified */ + time_msec_t m = u; /* default to 'units' if none specified */ - bool hasUnits = false; - if (0 == d) - (void) 0; - else if ((token = ConfigParser::PeekAtToken()) == NULL) - (void) 0; - else if ((m = parseTimeUnits(token, allowMsec)) == 0) { - if (!expectMoreArguments) + if (d) { + if ((token = ConfigParser::PeekAtToken()) && (m = parseTimeUnits(token, allowMsec))) { + (void)ConfigParser::NextToken(); + + } else if (!expectMoreArguments) { self_destruct(); - } else { //pop the token - (void)ConfigParser::NextToken(); - hasUnits = true; - } - if (!hasUnits) - debugs(3, DBG_CRITICAL, "WARNING: No units on '" << - config_input_line << "', assuming " << - d << " " << units ); + + } else { + token = NULL; // show default units if dying below + debugs(3, DBG_CRITICAL, "WARNING: No units on '" << config_input_line << "', assuming " << d << " " << units); + } + } else + token = NULL; // show default units if dying below. *tptr = static_cast(m * d); if (static_cast(*tptr) * 2 != m * d * 2) { - debugs(3, DBG_CRITICAL, "ERROR: Invalid value '" << - d << " " << token << ": integer overflow (time_msec_t)."); + debugs(3, DBG_CRITICAL, "FATAL: Invalid value '" << + d << " " << (token ? token : units) << ": integer overflow (time_msec_t)."); self_destruct(); } } -- 2.47.2