Patch for an Issue #979

This commit is contained in:
Miroslav Stampar 2014-12-01 00:29:25 +01:00
parent 56b6bf72f4
commit f71a65a9a0
3 changed files with 16 additions and 14 deletions

View File

@ -15,6 +15,7 @@ import tempfile
from lib.core.exception import SqlmapSystemException
from lib.core.settings import BIGARRAY_CHUNK_LENGTH
from lib.core.settings import BIGARRAY_TEMP_PREFIX
class Cache(object):
"""
@ -35,14 +36,12 @@ class BigArray(list):
self.chunks = [[]]
self.cache = None
self.filenames = set()
self.protected = False
self._os_remove = os.remove
def append(self, value):
self.chunks[-1].append(value)
if len(self.chunks[-1]) >= BIGARRAY_CHUNK_LENGTH:
filename = self._dump(self.chunks[-1])
del(self.chunks[-1][:])
self.chunks[-1] = filename
self.chunks.append([])
@ -65,7 +64,7 @@ class BigArray(list):
def _dump(self, value):
try:
handle, filename = tempfile.mkstemp(prefix="sqlmapba-")
handle, filename = tempfile.mkstemp(prefix=BIGARRAY_TEMP_PREFIX)
self.filenames.add(filename)
os.close(handle)
with open(filename, "w+b") as fp:
@ -85,12 +84,11 @@ class BigArray(list):
self.cache = Cache(index, pickle.load(fp), False)
def __getstate__(self):
self.protected = True
return self.chunks, self.filenames, self.protected
return self.chunks, self.filenames
def __setstate__(self, state):
self.__init__()
self.chunks, self.filenames, self.protected = state
self.chunks, self.filenames = state
def __getslice__(self, i, j):
retval = BigArray()
@ -132,11 +130,3 @@ class BigArray(list):
def __len__(self):
return len(self.chunks[-1]) if len(self.chunks) == 1 else (len(self.chunks) - 1) * BIGARRAY_CHUNK_LENGTH + len(self.chunks[-1])
def __del__(self):
if not self.protected:
for filename in self.filenames:
try:
self._os_remove(filename)
except:
pass

View File

@ -441,6 +441,9 @@ ROTATING_CHARS = ('\\', '|', '|', '/', '-')
# Chunk length (in items) used by BigArray objects (only last chunk and cached one are held in memory)
BIGARRAY_CHUNK_LENGTH = 4096
# Prefix used for storing dumped chunks in BigArray objects
BIGARRAY_TEMP_PREFIX = "sqlmapba-%d-" % os.getpid()
# Only console display last n table rows
TRIM_STDOUT_DUMP_SIZE = 256

View File

@ -6,11 +6,13 @@ See the file 'doc/COPYING' for copying permission
"""
import bdb
import glob
import inspect
import logging
import os
import re
import sys
import tempfile
import time
import traceback
import warnings
@ -42,6 +44,7 @@ from lib.core.exception import SqlmapUserQuitException
from lib.core.option import initOptions
from lib.core.option import init
from lib.core.profiling import profile
from lib.core.settings import BIGARRAY_TEMP_PREFIX
from lib.core.settings import LEGAL_DISCLAIMER
from lib.core.testing import smokeTest
from lib.core.testing import liveTest
@ -151,6 +154,12 @@ def main():
if conf.get("showTime"):
dataToStdout("\n[*] shutting down at %s\n\n" % time.strftime("%X"), forceOutput=True)
for filename in glob.glob("%s*" % os.path.join(tempfile.gettempdir(), BIGARRAY_TEMP_PREFIX)):
try:
os.remove(filename)
except:
pass
kb.threadContinue = False
kb.threadException = True