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

Skip to content

Commit f71a65a

Browse files
committed
Patch for an Issue #979
1 parent 56b6bf7 commit f71a65a

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

lib/core/bigarray.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from lib.core.exception import SqlmapSystemException
1717
from lib.core.settings import BIGARRAY_CHUNK_LENGTH
18+
from lib.core.settings import BIGARRAY_TEMP_PREFIX
1819

1920
class Cache(object):
2021
"""
@@ -35,14 +36,12 @@ def __init__(self):
3536
self.chunks = [[]]
3637
self.cache = None
3738
self.filenames = set()
38-
self.protected = False
3939
self._os_remove = os.remove
4040

4141
def append(self, value):
4242
self.chunks[-1].append(value)
4343
if len(self.chunks[-1]) >= BIGARRAY_CHUNK_LENGTH:
4444
filename = self._dump(self.chunks[-1])
45-
del(self.chunks[-1][:])
4645
self.chunks[-1] = filename
4746
self.chunks.append([])
4847

@@ -65,7 +64,7 @@ def index(self, value):
6564

6665
def _dump(self, value):
6766
try:
68-
handle, filename = tempfile.mkstemp(prefix="sqlmapba-")
67+
handle, filename = tempfile.mkstemp(prefix=BIGARRAY_TEMP_PREFIX)
6968
self.filenames.add(filename)
7069
os.close(handle)
7170
with open(filename, "w+b") as fp:
@@ -85,12 +84,11 @@ def _checkcache(self, index):
8584
self.cache = Cache(index, pickle.load(fp), False)
8685

8786
def __getstate__(self):
88-
self.protected = True
89-
return self.chunks, self.filenames, self.protected
87+
return self.chunks, self.filenames
9088

9189
def __setstate__(self, state):
9290
self.__init__()
93-
self.chunks, self.filenames, self.protected = state
91+
self.chunks, self.filenames = state
9492

9593
def __getslice__(self, i, j):
9694
retval = BigArray()
@@ -132,11 +130,3 @@ def __iter__(self):
132130

133131
def __len__(self):
134132
return len(self.chunks[-1]) if len(self.chunks) == 1 else (len(self.chunks) - 1) * BIGARRAY_CHUNK_LENGTH + len(self.chunks[-1])
135-
136-
def __del__(self):
137-
if not self.protected:
138-
for filename in self.filenames:
139-
try:
140-
self._os_remove(filename)
141-
except:
142-
pass

lib/core/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@
441441
# Chunk length (in items) used by BigArray objects (only last chunk and cached one are held in memory)
442442
BIGARRAY_CHUNK_LENGTH = 4096
443443

444+
# Prefix used for storing dumped chunks in BigArray objects
445+
BIGARRAY_TEMP_PREFIX = "sqlmapba-%d-" % os.getpid()
446+
444447
# Only console display last n table rows
445448
TRIM_STDOUT_DUMP_SIZE = 256
446449

sqlmap.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"""
77

88
import bdb
9+
import glob
910
import inspect
1011
import logging
1112
import os
1213
import re
1314
import sys
15+
import tempfile
1416
import time
1517
import traceback
1618
import warnings
@@ -42,6 +44,7 @@
4244
from lib.core.option import initOptions
4345
from lib.core.option import init
4446
from lib.core.profiling import profile
47+
from lib.core.settings import BIGARRAY_TEMP_PREFIX
4548
from lib.core.settings import LEGAL_DISCLAIMER
4649
from lib.core.testing import smokeTest
4750
from lib.core.testing import liveTest
@@ -151,6 +154,12 @@ def main():
151154
if conf.get("showTime"):
152155
dataToStdout("\n[*] shutting down at %s\n\n" % time.strftime("%X"), forceOutput=True)
153156

157+
for filename in glob.glob("%s*" % os.path.join(tempfile.gettempdir(), BIGARRAY_TEMP_PREFIX)):
158+
try:
159+
os.remove(filename)
160+
except:
161+
pass
162+
154163
kb.threadContinue = False
155164
kb.threadException = True
156165

0 commit comments

Comments
 (0)