Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed26dc0

Browse files
committed
Important patch for #3459
1 parent e8f505b commit ed26dc0

5 files changed

Lines changed: 60 additions & 11 deletions

File tree

lib/core/datatype.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import copy
99
import types
1010

11+
from thirdparty.odict.odict import OrderedDict
12+
1113
class AttribDict(dict):
1214
"""
1315
This class defines the sqlmap object, inheriting from Python data
@@ -104,3 +106,40 @@ def __init__(self):
104106
self.dbms = None
105107
self.dbms_version = None
106108
self.os = None
109+
110+
# Reference: https://www.kunxi.org/2014/05/lru-cache-in-python
111+
class LRUDict(object):
112+
def __init__(self, capacity):
113+
self.capacity = capacity
114+
self.cache = OrderedDict()
115+
116+
def __len__(self):
117+
return len(self.cache)
118+
119+
def __contains__(self, key):
120+
return key in self.cache
121+
122+
def __getitem__(self, key):
123+
try:
124+
value = self.cache.pop(key)
125+
self.cache[key] = value
126+
return value
127+
except KeyError:
128+
return -1
129+
130+
def get(self, key):
131+
return self.__getitem__(self, key)
132+
133+
def __setitem__(self, key, value):
134+
try:
135+
self.cache.pop(key)
136+
except KeyError:
137+
if len(self.cache) >= self.capacity:
138+
self.cache.popitem(last=False)
139+
self.cache[key] = value
140+
141+
def set(self, key, value):
142+
self.__setitem__(key, value)
143+
144+
def keys(self):
145+
return self.cache.keys()

lib/core/decorators.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77

88
import functools
99
import hashlib
10+
import threading
1011

12+
from lib.core.settings import MAX_CACHE_ITEMS
13+
from lib.core.datatype import LRUDict
1114
from lib.core.threads import getCurrentThreadData
1215

13-
def cachedmethod(f, cache={}):
16+
_lock = threading.Lock()
17+
18+
def cachedmethod(f, cache=LRUDict(capacity=MAX_CACHE_ITEMS)):
1419
"""
1520
Method with a cached content
1621
@@ -19,11 +24,12 @@ def cachedmethod(f, cache={}):
1924

2025
@functools.wraps(f)
2126
def _(*args, **kwargs):
22-
key = int(hashlib.md5("|".join(str(_) for _ in (f, args, kwargs))).hexdigest(), 16) & 0x7fffffffffffffff
23-
if key not in cache:
24-
cache[key] = f(*args, **kwargs)
27+
with _lock:
28+
key = int(hashlib.md5("|".join(str(_) for _ in (f, args, kwargs))).hexdigest(), 16) & 0x7fffffffffffffff
29+
if key not in cache:
30+
cache[key] = f(*args, **kwargs)
2531

26-
return cache[key]
32+
return cache[key]
2733

2834
return _
2935

lib/core/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.3.1.80"
22+
VERSION = "1.3.1.81"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -166,6 +166,9 @@
166166
# In case of missing piece of partial union dump, buffered array must be flushed after certain size
167167
MAX_BUFFERED_PARTIAL_UNION_LENGTH = 1024
168168

169+
# Maximum size of cache used in @cachedmethod decorator
170+
MAX_CACHE_ITEMS = 256
171+
169172
# Suffix used for naming meta databases in DBMS(es) without explicit database name
170173
METADB_SUFFIX = "_masterdb"
171174

thirdparty/odict/odict.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def pop(self, key, *args):
621621
raise KeyError(key)
622622
return val
623623

624-
def popitem(self, i=-1):
624+
def popitem(self, last=True):
625625
"""
626626
Delete and return an item specified by index, not a random one as in
627627
dict. The index is -1 by default (the last item).
@@ -643,6 +643,7 @@ def popitem(self, i=-1):
643643
if not self._sequence:
644644
raise KeyError('popitem(): dictionary is empty')
645645
try:
646+
i = -1 if last else 0
646647
key = self._sequence[i]
647648
except IndexError:
648649
raise IndexError('popitem(): index %s not valid' % i)

txt/checksum.md5

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ a932126e7d80e545c5d44af178d0bc0c lib/core/bigarray.py
3333
f97e6dc62b453cc787ef7f801ee1af5b lib/core/common.py
3434
de8d27ae6241163ff9e97aa9e7c51a18 lib/core/convert.py
3535
abcb1121eb56d3401839d14e8ed06b6e lib/core/data.py
36-
db60c6ebb63b72ed119e304b359fc1a6 lib/core/datatype.py
37-
b7c912e2af7a3354f6d7c04f556a80b2 lib/core/decorators.py
36+
e1f7758f433202c50426efde5eb96768 lib/core/datatype.py
37+
1646402a733e564f05025e848b323cf9 lib/core/decorators.py
3838
5f4680b769ae07f22157bd832c97cf8f lib/core/defaults.py
3939
9dfc69ba47209a4ceca494dde9ee8183 lib/core/dicts.py
4040
4782353a3072e4d17c4e314daf918d8a lib/core/dump.py
@@ -50,7 +50,7 @@ fe370021c6bc99daf44b2bfc0d1effb3 lib/core/patch.py
5050
7d8a22c582ad201f65b73225e4456170 lib/core/replication.py
5151
3179d34f371e0295dd4604568fb30bcd lib/core/revision.py
5252
d6269c55789f78cf707e09a0f5b45443 lib/core/session.py
53-
18eeffa589e845f62a7c0452ba3c373a lib/core/settings.py
53+
e9e5e6207591b134c0cf4ecf8e712ea9 lib/core/settings.py
5454
4483b4a5b601d8f1c4281071dff21ecc lib/core/shell.py
5555
10fd19b0716ed261e6d04f311f6f527c lib/core/subprocessng.py
5656
9c7b5c6397fb3da33e7a4d7876d159c6 lib/core/target.py
@@ -358,7 +358,7 @@ bf318e0abbe6b2e1a167a233db7f744f thirdparty/magic/magic.py
358358
d41d8cd98f00b204e9800998ecf8427e thirdparty/multipart/__init__.py
359359
82432cb4ef575aa16900ba221cc1dc98 thirdparty/multipart/multipartpost.py
360360
3e502b04f3849afbb7f0e13b5fd2b5c1 thirdparty/odict/__init__.py
361-
4174fad6be204761db349032341b7582 thirdparty/odict/odict.py
361+
74048dca0470bc78af73f0aafccfd069 thirdparty/odict/odict.py
362362
0105f1734f326704d2d68839084ca661 thirdparty/oset/_abc.py
363363
54a861de0f08bb80c2e8846579ec83bd thirdparty/oset/__init__.py
364364
6c79e6d14e031beebe6de127b53c7c93 thirdparty/oset/pyoset.py

0 commit comments

Comments
 (0)