You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2012/03/15 00:23:29 UTC
git commit: TS-1138: Fix off by one range error in IpMap
Updated Branches:
refs/heads/master 75c6dd83c -> 64f2131c1
TS-1138: Fix off by one range error in IpMap
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/64f2131c
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/64f2131c
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/64f2131c
Branch: refs/heads/master
Commit: 64f2131c1ab57936e88a79f579820bf49a61219e
Parents: 75c6dd8
Author: Alan M. Carroll <am...@network-geographics.com>
Authored: Wed Mar 14 15:20:55 2012 -0500
Committer: Alan M. Carroll <am...@network-geographics.com>
Committed: Wed Mar 14 18:22:32 2012 -0500
----------------------------------------------------------------------
CHANGES | 2 ++
lib/ts/IpMap.cc | 15 +++++++--------
lib/ts/IpMapTest.cc | 28 ++++++++++++++++++++++++++--
3 files changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/64f2131c/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index aa8b06c..c551a42 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,7 @@
-*- coding: utf-8 -*-
Changes with Apache Traffic Server 3.1.3
+ *) [TS-1138] Fixed off by one range error in IpMap.s
+
*) [TS-462] Support TLS Server Name Indication (SNI)
*) [TS-1134] TSNetAcceptNamedProtocol should fail if NPN is not supported.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/64f2131c/lib/ts/IpMap.cc
----------------------------------------------------------------------
diff --git a/lib/ts/IpMap.cc b/lib/ts/IpMap.cc
index e312b3c..7c2b157 100644
--- a/lib/ts/IpMap.cc
+++ b/lib/ts/IpMap.cc
@@ -1007,9 +1007,7 @@ protected:
self& setMaxMinusOne(
ArgType max ///< One more than maximum value.
) {
- this->setMax(max);
- dec(_max);
- return *this;
+ return this->setMax(max-1);
}
/** Set the minimum value to one more than @a min.
@return This object.
@@ -1017,14 +1015,15 @@ protected:
self& setMinPlusOne(
ArgType min ///< One less than minimum value.
) {
- this->setMin(min);
- inc(_max);
- return *this;
+ return this->setMin(min+1);
}
/** Decremement the maximum value in place.
@return This object.
*/
- self& decrementMax() { dec(_max); return *this; }
+ self& decrementMax() {
+ this->setMax(_max-1);
+ return *this;
+ }
/// Increment a metric.
static void inc(
@@ -1160,7 +1159,7 @@ protected:
Metric const& min ///< One less than minimum value.
) {
this->setMin(min);
- inc(_max);
+ inc(_min);
return *this;
}
/** Decremement the maximum value in place.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/64f2131c/lib/ts/IpMapTest.cc
----------------------------------------------------------------------
diff --git a/lib/ts/IpMapTest.cc b/lib/ts/IpMapTest.cc
index 7a8d385..5b034b7 100644
--- a/lib/ts/IpMapTest.cc
+++ b/lib/ts/IpMapTest.cc
@@ -87,16 +87,26 @@ REGRESSION_TEST(IpMap_Test_Basic)(RegressionTest* t, int atype, int* pstatus) {
check(t, pstatus, !map.contains(ip140), "Test 3 - unmark left edge still there.");
check(t, pstatus, !map.contains(ip150), "Test 3 - unmark middle still there.");
check(t, pstatus, !map.contains(ip160), "Test 3 - unmark right edge still there.");
+
+ map.clear();
+ map.mark(ip20,ip20, markA);
+ check(t, pstatus, map.contains(ip20), "Map failed on singleton insert");
+ map.mark(ip10, ip200, markB);
+ mark=0;
+ map.contains(ip20, &mark);
+ check(t, pstatus, mark == markB, "Map held singleton against range.");
+
}
-REGRESSION_TEST(IpMap_Test_Sample)(RegressionTest* t, int atype, int* pstatus) {
+REGRESSION_TEST(IpMap_Test_Fill)(RegressionTest* t, int atype, int* pstatus) {
IpMap map;
+ ip_text_buffer ipb1, ipb2;
void* const allow = reinterpret_cast<void*>(1);
void* const deny = reinterpret_cast<void*>(2);
void* mark; // for retrieval
IpEndpoint a1,a2,a3,a4,a5,a6, a7, a8;
- IpEndpoint target;
+ IpEndpoint target, a_loopback;
IpEndpoint t6;
*pstatus = REGRESSION_TEST_PASSED;
@@ -111,6 +121,7 @@ REGRESSION_TEST(IpMap_Test_Sample)(RegressionTest* t, int atype, int* pstatus) {
ats_ip_pton("fe80::221:9bff:fe10:9d9d", &a8);
ats_ip_pton("10.28.56.4", &target);
ats_ip_pton("fe80::221:9bff:fe10:9d95", &t6);
+ ats_ip_pton("127.0.0.1", &a_loopback);
map.fill(&a1,&a2,deny);
map.fill(&a3,&a4,allow);
@@ -130,4 +141,17 @@ REGRESSION_TEST(IpMap_Test_Sample)(RegressionTest* t, int atype, int* pstatus) {
check(t, pstatus, map.contains(&t6,&mark), "IpMap Sample: T6 not found.");
check(t, pstatus, mark == deny, "IpMap Sample: Bad T6 value. Expected deny, got allow.");
+ map.clear();
+ map.fill(&a_loopback, &a_loopback, allow);
+ check(t, pstatus, map.contains(&a_loopback), "Map fill: singleton not marked.");
+ map.fill(&a3, &a4, deny);
+
+ mark=0;
+ check(t, pstatus, map.contains(&a_loopback, &mark), "Map fill: singleton marking lost.");
+ check(t, pstatus, mark == allow, "Map fill: overwrote existing singleton mark.");
+ if (check(t, pstatus, map.begin() != map.end(), "Map fill: map is empty.")) {
+ if (check(t, pstatus, ++(map.begin()) != map.end(), "Map fill: only one range.")) {
+ check(t, pstatus, -1 == ats_ip_addr_cmp(map.begin()->max(), (++map.begin())->min()), "Map fill: ranges not disjoint [%s < %s].", ats_ip_ntop(map.begin()->max(), ipb1, sizeof(ipb1)), ats_ip_ntop((++map.begin())->min(), ipb2, sizeof(ipb2)));
+ }
+ }
}