From: Amos Jeffries Date: Wed, 4 Nov 2015 16:42:55 +0000 (-0800) Subject: Bug 4374: refresh_pattern config parser (%) X-Git-Tag: SQUID_4_0_3~43 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1454480ab15586f71f8fa82ed8b3e1742950c515;p=thirdparty%2Fsquid.git Bug 4374: refresh_pattern config parser (%) --- diff --git a/src/Parsing.cc b/src/Parsing.cc index 8bd59c2275..a8a5769f52 100644 --- a/src/Parsing.cc +++ b/src/Parsing.cc @@ -163,14 +163,15 @@ GetInteger(void) * the percentage symbol (%) and we check whether the value is in the range * of [0, 100] * So, we accept two types of input: 1. XX% or 2. XX , 0<=XX<=100 + * unless the limit parameter is set to false. */ -int -GetPercentage(void) +double +GetPercentage(bool limit) { char *token = ConfigParser::NextToken(); if (!token) { - debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: A percentage value is missing."); + debugs(3, DBG_CRITICAL, "FATAL: A percentage value is missing."); self_destruct(); } @@ -182,12 +183,12 @@ GetPercentage(void) int p = xatoi(token); - if (p < 0 || p > 100) { - debugs(0, DBG_PARSE_NOTE(DBG_IMPORTANT), "ERROR: The value '" << token << "' is out of range. A percentage should be within [0, 100]."); + if (p < 0 || (limit && p > 100)) { + debugs(3, DBG_CRITICAL, "FATAL: The value '" << token << "' is out of range. A percentage should be within [0, 100]."); self_destruct(); } - return p; + return static_cast(p) / 100.0; } unsigned short diff --git a/src/Parsing.h b/src/Parsing.h index 2f69b0f5e8..acf23abeef 100644 --- a/src/Parsing.h +++ b/src/Parsing.h @@ -36,10 +36,14 @@ int GetInteger(void); * Parse a percentage value, e.g., 20%. * The behavior of this function is similar as GetInteger(). * The difference is that the token might contain '%' as percentage symbol (%), - * and we further check whether the value is in the range of [0, 100] + * and we may further check whether the value is in the range of [0, 100]. * For example, 20% and 20 are both valid tokens, while 101%, 101, -1 are invalid. + * + * \param limit whether to check the value is within 0-100% limit + * + * \return the percentage as a decimal number. ie 100% = 1.00, 50% = 0.5 */ -int GetPercentage(void); +double GetPercentage(bool limit = true); unsigned short GetShort(void); diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 85d7feec40..fdcbdac59d 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -2662,9 +2662,7 @@ parse_refreshpattern(RefreshPattern ** head) min = (time_t) (i * 60); /* convert minutes to seconds */ - i = GetPercentage(); /* token: pct */ - - pct = (double) i / 100.0; + pct = GetPercentage(false); /* token: pct . with no limit on size */ i = GetInteger(); /* token: max */ diff --git a/test-suite/squidconf/regressions-4.0 b/test-suite/squidconf/regressions-4.0 new file mode 100644 index 0000000000..05778a8b8d --- /dev/null +++ b/test-suite/squidconf/regressions-4.0 @@ -0,0 +1,15 @@ +## Copyright (C) 1996-2015 The Squid Software Foundation and contributors +## +## Squid software is distributed under GPLv2+ license and includes +## contributions from numerous individuals and organizations. +## Please see the COPYING and CONTRIBUTORS files for details. +## + +# +# This file contains the list of reported regression cases in 4.0.x parser +# it covers: +# refresh_pattern + +# pct field parser +refresh_pattern . 1 1000% 60 +refresh_pattern . 1 0% 60