Fix for an Issue #650

This commit is contained in:
Miroslav Stampar 2014-03-24 10:46:23 +01:00
parent 106102bd3c
commit f6e1d9e026
2 changed files with 26 additions and 4 deletions

View File

@ -460,6 +460,9 @@ HASHDB_FLUSH_THRESHOLD = 32
# Number of retries for unsuccessful HashDB flush attempts
HASHDB_FLUSH_RETRIES = 3
# Number of retries for unsuccessful HashDB end transaction attempts
HASHDB_END_TRANSACTION_RETRIES = 3
# Unique milestone value used for forced deprecation of old HashDB values (e.g. when changing hash/pickle mechanism)
HASHDB_MILESTONE_VALUE = "cAWxkLYCQT" # r5129 "".join(random.sample(string.ascii_letters, 10))

View File

@ -16,6 +16,7 @@ from lib.core.common import serializeObject
from lib.core.common import unserializeObject
from lib.core.data import logger
from lib.core.exception import SqlmapDataException
from lib.core.settings import HASHDB_END_TRANSACTION_RETRIES
from lib.core.settings import HASHDB_FLUSH_RETRIES
from lib.core.settings import HASHDB_FLUSH_THRESHOLD
from lib.core.settings import UNICODE_ENCODING
@ -43,7 +44,11 @@ class HashDB(object):
return threadData.hashDBCursor
cursor = property(_get_cursor)
def _set_cursor(self, cursor):
threadData = getCurrentThreadData()
threadData.hashDBCursor = cursor
cursor = property(_get_cursor, _set_cursor)
def close(self):
threadData = getCurrentThreadData()
@ -134,15 +139,29 @@ class HashDB(object):
def beginTransaction(self):
threadData = getCurrentThreadData()
if not threadData.inTransaction:
self.cursor.execute('BEGIN TRANSACTION')
self.cursor.execute("BEGIN TRANSACTION")
threadData.inTransaction = True
def endTransaction(self):
threadData = getCurrentThreadData()
if threadData.inTransaction:
retries = 0
while retries < HASHDB_END_TRANSACTION_RETRIES:
try:
self.cursor.execute("END TRANSACTION")
threadData.inTransaction = False
except sqlite3.OperationalError:
pass
else:
return
retries += 1
time.sleep(1)
try:
self.cursor.execute('END TRANSACTION')
self.cursor.execute("ROLLBACK TRANSACTION")
except sqlite3.OperationalError:
pass
self.cursor.close()
self.cursor = None
finally:
threadData.inTransaction = False