Skip to content

Commit fccdb82

Browse files
committed
Patch for an Issue sqlmapproject#193
1 parent c9e7e71 commit fccdb82

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/core/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@
402402
# Skip unforced HashDB flush requests below the threshold number of cached items
403403
HASHDB_FLUSH_THRESHOLD = 32
404404

405+
# Number of retries for unsuccessful HashDB flush attempts
406+
HASHDB_FLUSH_RETRIES = 3
407+
405408
# Unique milestone value used for forced deprecation of old HashDB values (e.g. when changing hash/pickle mechanism)
406409
HASHDB_MILESTONE_VALUE = "cAWxkLYCQT" # r5129 "".join(random.sample(string.letters, 10))
407410

lib/utils/hashdb.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from lib.core.common import getUnicode
1515
from lib.core.common import serializeObject
1616
from lib.core.common import unserializeObject
17+
from lib.core.data import logger
18+
from lib.core.settings import HASHDB_FLUSH_RETRIES
1719
from lib.core.settings import HASHDB_FLUSH_THRESHOLD
1820
from lib.core.settings import UNICODE_ENCODING
1921
from lib.core.threads import getCurrentThreadData
@@ -95,16 +97,24 @@ def flush(self, forced=False):
9597
try:
9698
self.beginTransaction()
9799
for hash_, value in _.items():
100+
retries = 0
98101
while True:
99102
try:
100103
try:
101104
self.cursor.execute("INSERT INTO storage VALUES (?, ?)", (hash_, value,))
102105
except sqlite3.IntegrityError:
103106
self.cursor.execute("UPDATE storage SET value=? WHERE id=?", (value, hash_,))
104107
except sqlite3.OperationalError, ex:
105-
if not any(_ in ex.message for _ in ('locked', 'I/O')):
106-
raise
108+
109+
if retries == 0:
110+
warnMsg = "there has been a problem while writing to "
111+
warnMsg += "the session file ('%s')" % ex.message
112+
logger.warn(warnMsg)
113+
114+
if retries >= HASHDB_FLUSH_RETRIES:
115+
return
107116
else:
117+
retries += 1
108118
time.sleep(1)
109119
else:
110120
break

0 commit comments

Comments
 (0)