Blame SOURCES/0043-fix-LastUpdatedOrderedDict-__getitem__-fetch-from-li.patch

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