Skip to content

Commit 13de836

Browse files
committed
Major silent bug fix to multi-threading functionality. Thanks Nico Leidecker for reporting!
1 parent f7ee4d5 commit 13de836

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

lib/techniques/blind/inference.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,38 +140,34 @@ def etaProgressUpdate(charTime, index):
140140

141141

142142
def downloadThread():
143-
while True:
144-
idxlock.acquire()
145-
146-
if index[0] >= length:
147-
idxlock.release()
148-
149-
return
143+
try:
144+
while True:
145+
idxlock.acquire()
150146

151-
index[0] += 1
152-
curidx = index[0]
153-
idxlock.release()
147+
if index[0] >= length:
148+
idxlock.release()
154149

155-
charStart = time.time()
156-
val = getChar(curidx)
150+
return
157151

158-
if val == None:
159-
raise sqlmapValueException, "failed to get character at index %d (expected %d total)" % (curidx, length)
152+
index[0] += 1
153+
curidx = index[0]
154+
idxlock.release()
160155

161-
value[curidx-1] = val
156+
charStart = time.time()
157+
val = getChar(curidx)
162158

163-
if showEta:
164-
etaProgressUpdate(time.time() - charStart, index[0])
165-
elif conf.verbose in ( 1, 2 ):
166-
s = "".join([c or "_" for c in value])
167-
iolock.acquire()
168-
dataToStdout("\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), s))
169-
iolock.release()
159+
if val == None:
160+
raise sqlmapValueException, "failed to get character at index %d (expected %d total)" % (curidx, length)
170161

162+
value[curidx-1] = val
171163

172-
def downloadThreadProxy(numThread):
173-
try:
174-
downloadThread()
164+
if showEta:
165+
etaProgressUpdate(time.time() - charStart, index[0])
166+
elif conf.verbose in ( 1, 2 ):
167+
s = "".join([c or "_" for c in value])
168+
iolock.acquire()
169+
dataToStdout("\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), s))
170+
iolock.release()
175171

176172
except (sqlmapConnectionException, sqlmapValueException), errMsg:
177173
conf.threadException = True
@@ -199,7 +195,7 @@ def downloadThreadProxy(numThread):
199195

200196
# Start the threads
201197
for numThread in range(numThreads):
202-
thread = threading.Thread(target=downloadThreadProxy(numThread))
198+
thread = threading.Thread(target=downloadThread)
203199
thread.start()
204200
threads.append(thread)
205201

0 commit comments

Comments
 (0)