Skip to content

Commit 06ff8b3

Browse files
committed
Patch for an Issue sqlmapproject#1105
1 parent 8e03f4d commit 06ff8b3

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

lib/core/bigarray.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from lib.core.exception import SqlmapSystemException
1919
from lib.core.settings import BIGARRAY_CHUNK_SIZE
20-
from lib.core.settings import BIGARRAY_TEMP_PREFIX
2120

2221
DEFAULT_SIZE_OF = sys.getsizeof(object())
2322

@@ -92,7 +91,7 @@ def index(self, value):
9291

9392
def _dump(self, chunk):
9493
try:
95-
handle, filename = tempfile.mkstemp(prefix=BIGARRAY_TEMP_PREFIX)
94+
handle, filename = tempfile.mkstemp()
9695
self.filenames.add(filename)
9796
os.close(handle)
9897
with open(filename, "w+b") as fp:

lib/core/option.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import socket
1616
import string
1717
import sys
18+
import tempfile
1819
import threading
1920
import time
2021
import urllib2
@@ -1437,6 +1438,17 @@ def _checkDependencies():
14371438
if conf.dependencies:
14381439
checkDependencies()
14391440

1441+
def _createTemporaryDirectory():
1442+
"""
1443+
Creates temporary directory for this run.
1444+
"""
1445+
1446+
if not os.path.isdir(tempfile.gettempdir()):
1447+
os.makedirs(tempfile.gettempdir())
1448+
tempfile.tempdir = tempfile.mkdtemp(prefix="sqlmap", suffix=str(os.getpid()))
1449+
if not os.path.isdir(tempfile.tempdir):
1450+
os.makedirs(tempfile.tempdir)
1451+
14401452
def _cleanupOptions():
14411453
"""
14421454
Cleanup configuration attributes.
@@ -2332,6 +2344,7 @@ def init():
23322344
_cleanupOptions()
23332345
_purgeOutput()
23342346
_checkDependencies()
2347+
_createTemporaryDirectory()
23352348
_basicOptionValidation()
23362349
_setProxyList()
23372350
_setTorProxySettings()

lib/core/settings.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,6 @@
446446
# Approximate chunk length (in bytes) used by BigArray objects (only last chunk and cached one are held in memory)
447447
BIGARRAY_CHUNK_SIZE = 1024 * 1024
448448

449-
# Prefix used for storing dumped chunks in BigArray objects
450-
BIGARRAY_TEMP_PREFIX = "sqlmapba-%d-" % os.getpid()
451-
452449
# Only console display last n table rows
453450
TRIM_STDOUT_DUMP_SIZE = 256
454451

sqlmap.py

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

88
import bdb
9-
import glob
109
import inspect
1110
import logging
1211
import os
1312
import re
13+
import shutil
1414
import sys
1515
import tempfile
1616
import time
@@ -44,7 +44,6 @@
4444
from lib.core.option import initOptions
4545
from lib.core.option import init
4646
from lib.core.profiling import profile
47-
from lib.core.settings import BIGARRAY_TEMP_PREFIX
4847
from lib.core.settings import LEGAL_DISCLAIMER
4948
from lib.core.testing import smokeTest
5049
from lib.core.testing import liveTest
@@ -154,11 +153,7 @@ def main():
154153
if conf.get("showTime"):
155154
dataToStdout("\n[*] shutting down at %s\n\n" % time.strftime("%X"), forceOutput=True)
156155

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
156+
shutil.rmtree(tempfile.tempdir, ignore_errors=True)
162157

163158
kb.threadContinue = False
164159
kb.threadException = True

0 commit comments

Comments
 (0)