]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4374: refresh_pattern config parser (%)
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 4 Nov 2015 16:42:55 +0000 (08:42 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 4 Nov 2015 16:42:55 +0000 (08:42 -0800)
src/Parsing.cc
src/Parsing.h
src/cache_cf.cc
test-suite/squidconf/regressions-4.0 [new file with mode: 0644]

index 8bd59c227516b4387824b273fb1370477ac4d5b6..a8a5769f52c7a6ab40d1c11b3f9034cf35a37923 100644 (file)
@@ -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<double>(p) / 100.0;
 }
 
 unsigned short
index 2f69b0f5e8acda8ab857a235a3d1e1f134e521c5..acf23abeef0e8211bc23b3986cc857544dfbe568 100644 (file)
@@ -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);
 
index 85d7feec4083e0334ed10b24cca5ba2f38d2f150..fdcbdac59d914b6c0a40fbcaca8d312272c35b7a 100644 (file)
@@ -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 (file)
index 0000000..05778a8
--- /dev/null
@@ -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