Skip to content

Commit

Permalink
Fix in asyncio mode as well
Browse files Browse the repository at this point in the history
  • Loading branch information
shelld3v committed Nov 7, 2024
1 parent e542593 commit f776055
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions lib/core/fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __init__(
self._requester = requester
self._dictionary = dictionary
self._base_path: str = ""
self.exc: Exception | None = None
self.match_callbacks = match_callbacks
self.not_found_callbacks = not_found_callbacks
self.error_callbacks = error_callbacks
Expand Down Expand Up @@ -148,6 +147,7 @@ def __init__(
not_found_callbacks=not_found_callbacks,
error_callbacks=error_callbacks,
)
self._exc: Exception | None = None
self._threads = []
self._play_event = threading.Event()
self._quit_event = threading.Event()
Expand Down Expand Up @@ -207,8 +207,8 @@ def start(self) -> None:
thread.start()

def is_finished(self) -> bool:
if self.exc:
raise self.exc
if self._exc:
raise self._exc

for thread in self._threads:
if thread.is_alive():
Expand Down Expand Up @@ -266,7 +266,7 @@ def thread_proc(self) -> None:
break

except Exception as e:
self.exc = e
self._exc = e

finally:
time.sleep(options["delay"])
Expand Down Expand Up @@ -358,12 +358,6 @@ async def start(self) -> None:

await asyncio.gather(*self._background_tasks)

def is_finished(self) -> bool:
if self.exc:
raise self.exc

return len(self._background_tasks) == 0

def play(self) -> None:
self._play_event.set()

Expand All @@ -376,7 +370,12 @@ def quit(self) -> None:

async def scan(self, path: str) -> None:
scanners = self.get_scanners_for(path)
response = await self._requester.request(path)
try:
response = await self._requester.request(path)
except RequestException as e:
for callback in self.error_callbacks:
callback(e)
return

if self.is_excluded(response):
for callback in self.not_found_callbacks:
Expand All @@ -390,11 +389,8 @@ async def scan(self, path: str) -> None:
callback(response)
return

try:
for callback in self.match_callbacks:
callback(response)
except Exception as e:
self.exc = e
for callback in self.match_callbacks:
callback(response)

async def task_proc(self) -> None:
async with self.sem:
Expand All @@ -405,8 +401,5 @@ async def task_proc(self) -> None:
await self.scan(self._base_path + path)
except StopIteration:
pass
except RequestException as e:
for callback in self.error_callbacks:
callback(e)
finally:
await asyncio.sleep(options["delay"])

0 comments on commit f776055

Please sign in to comment.