|
|
8072fb |
From d76d54277bc51398f7aa20b3dce0863e3520810b Mon Sep 17 00:00:00 2001
|
|
|
8072fb |
From: Eric Garver <eric@garver.life>
|
|
|
8072fb |
Date: Wed, 29 Jul 2020 15:18:38 -0400
|
|
|
8072fb |
Subject: [PATCH 43/45] fix(LastUpdatedOrderedDict): __getitem__(): fetch from
|
|
|
8072fb |
list if int
|
|
|
8072fb |
|
|
|
8072fb |
If the LastUpdatedOrderedDict contains a boolean key, e.g.
|
|
|
8072fb |
|
|
|
8072fb |
myLastUpdatedOrderedDict = LastUpdatedOrderedDict()
|
|
|
8072fb |
myLastUpdatedOrderedDic[True] = "true"
|
|
|
8072fb |
|
|
|
8072fb |
then
|
|
|
8072fb |
|
|
|
8072fb |
myLastUpdatedOrderedDic[1]
|
|
|
8072fb |
|
|
|
8072fb |
yields "true". As such, using the LastUpdatedOrderedDict as an iterable
|
|
|
8072fb |
e.g.
|
|
|
8072fb |
|
|
|
8072fb |
for foo in myLastUpdatedOrderedDict:
|
|
|
8072fb |
...
|
|
|
8072fb |
|
|
|
8072fb |
would mean that the for loop tries integer indexes 0 (returns key True),
|
|
|
8072fb |
and then 1 (also returns key True). This caused duplicate walks of a key
|
|
|
8072fb |
True if it was the first key in the LastUpdatedOrderedDict.
|
|
|
8072fb |
|
|
|
8072fb |
This occurs because
|
|
|
8072fb |
|
|
|
8072fb |
>>> True == 1
|
|
|
8072fb |
True
|
|
|
8072fb |
>>> False == 0
|
|
|
8072fb |
True
|
|
|
8072fb |
|
|
|
8072fb |
(cherry picked from commit 55754b65be6eaa697382992679e6673346e39f78)
|
|
|
8072fb |
(cherry picked from commit 1561dbc6c2b8f8f7f27b89810a8dda9b869b1923)
|
|
|
8072fb |
---
|
|
|
8072fb |
src/firewall/fw_types.py | 6 +++---
|
|
|
8072fb |
1 file changed, 3 insertions(+), 3 deletions(-)
|
|
|
8072fb |
|
|
|
8072fb |
diff --git a/src/firewall/fw_types.py b/src/firewall/fw_types.py
|
|
|
8072fb |
index 07c69c61702f..3d90c1812aec 100644
|
|
|
8072fb |
--- a/src/firewall/fw_types.py
|
|
|
8072fb |
+++ b/src/firewall/fw_types.py
|
|
|
8072fb |
@@ -54,10 +54,10 @@ class LastUpdatedOrderedDict(object):
|
|
|
8072fb |
self._dict[key] = value
|
|
|
8072fb |
|
|
|
8072fb |
def __getitem__(self, key):
|
|
|
8072fb |
- if key in self._dict:
|
|
|
8072fb |
- return self._dict[key]
|
|
|
8072fb |
- else:
|
|
|
8072fb |
+ if type(key) == int:
|
|
|
8072fb |
return self._list[key]
|
|
|
8072fb |
+ else:
|
|
|
8072fb |
+ return self._dict[key]
|
|
|
8072fb |
|
|
|
8072fb |
def __len__(self):
|
|
|
8072fb |
return len(self._list)
|
|
|
8072fb |
--
|
|
|
8072fb |
2.27.0
|
|
|
8072fb |
|