fix for Bug #166 (Keyboard interrupt in Python threading)

This commit is contained in:
Miroslav Stampar 2010-03-11 11:14:20 +00:00
parent b344a70ba1
commit 2c053d5cfb
2 changed files with 33 additions and 16 deletions

View File

@ -960,6 +960,7 @@ def __setConfAttributes():
conf.seqLock = None conf.seqLock = None
conf.sessionFP = None conf.sessionFP = None
conf.start = True conf.start = True
conf.threadContinue = True
conf.threadException = False conf.threadException = False
conf.wFileType = None conf.wFileType = None

View File

@ -154,10 +154,11 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
idxlock = threading.Lock() idxlock = threading.Lock()
iolock = threading.Lock() iolock = threading.Lock()
conf.seqLock = threading.Lock() conf.seqLock = threading.Lock()
conf.threadContinue = True
def downloadThread(): def downloadThread():
try: try:
while True: while conf.threadContinue:
idxlock.acquire() idxlock.acquire()
if index[0] >= length: if index[0] >= length:
@ -169,14 +170,17 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
curidx = index[0] curidx = index[0]
idxlock.release() idxlock.release()
if conf.threadContinue:
charStart = time.time() charStart = time.time()
val = getChar(curidx) val = getChar(curidx)
if val is None: if val is None:
raise sqlmapValueException, "failed to get character at index %d (expected %d total)" % (curidx, length) raise sqlmapValueException, "failed to get character at index %d (expected %d total)" % (curidx, length)
else:
break
value[curidx-1] = val value[curidx-1] = val
if conf.threadContinue:
if showEta: if showEta:
etaProgressUpdate(time.time() - charStart, index[0]) etaProgressUpdate(time.time() - charStart, index[0])
elif conf.verbose >= 1: elif conf.verbose >= 1:
@ -215,8 +219,20 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
threads.append(thread) threads.append(thread)
# And wait for them to all finish # And wait for them to all finish
#for thread in threads:
# thread.join()
try:
alive = True
while alive:
alive = False
for thread in threads: for thread in threads:
thread.join() if thread.isAlive():
alive = True
thread.join(5)
except KeyboardInterrupt:
conf.threadContinue = False
raise
# If we have got one single character not correctly fetched it # If we have got one single character not correctly fetched it
# can mean that the connection to the target url was lost # can mean that the connection to the target url was lost