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

Skip to content

Commit 1e72551

Browse files
author
Daniele Linguaglossa
committed
Fixed hang with loop programs
1 parent 9d75927 commit 1e72551

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

pyjfuzz/core/pjf_executor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from pjf_logger import PJFLogger
2929
from select import error
3030
import subprocess
31+
import signal
3132
import time
3233

3334
class PJFExecutor(object):
@@ -45,6 +46,12 @@ def __init__(self, arg=None):
4546
self.return_code = 0
4647
self._in = ""
4748
self.logger.debug("[{0}] - PJFExecutor successfully initialized".format(time.strftime("%H:%M:%S")))
49+
signal.signal(signal.SIGALRM, self.handle_alarm)
50+
51+
def handle_alarm(self, *args):
52+
signal.alarm(0)
53+
self.close()
54+
self.return_code = -1
4855

4956
def spawn(self, cmd, stdin_content="", stdin=False, shell=False, timeout=2):
5057
"""
@@ -59,7 +66,11 @@ def spawn(self, cmd, stdin_content="", stdin=False, shell=False, timeout=2):
5966
raise PJFInvalidType(type(stdin), bool)
6067
self._in = stdin_content
6168
try:
69+
signal.alarm(1)
6270
self.process = subprocess.Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE, shell=shell)
71+
self.process.wait()
72+
if self.return_code == -1:
73+
return
6374
self.finish_read(timeout, stdin_content, stdin)
6475
if self.process.poll() is not None:
6576
self.close()

pyjfuzz/core/pjf_external_fuzzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, configuration):
4848
def execute_sigsegv(self, obj):
4949
self.execute(obj)
5050
self.logger.debug("[{0}] - PJFExternalFuzzer successfully completed".format(time.strftime("%H:%M:%S")))
51-
return self.return_code in [-11, -6]
51+
return self.return_code in [-11, -6, -1]
5252

5353
def execute(self, obj):
5454
"""

pyjfuzz/core/pjf_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def fuzz_external(self, stdin_input=False):
203203
setattr(self.config, "temp_file_name", False)
204204
result = PJFExternalFuzzer(self.config).execute_sigsegv(j_fuzz)
205205
if result:
206-
print "[\033[92mINFO\033[0m] Program crashed with \033[91mSIGSEGV\033[0m/\033[91mSIGABRT\033[0m"
206+
print "[\033[92mINFO\033[0m] Program crashed with \033[91mSIGSEGV\033[0m/\033[91mSIGABRT\033[0m/\033[91mSIGHUP\033[0m"
207207
if self.config.debug:
208208
print "[\033[92mINFO\033[0m] Saving testcase..."
209209
try:

0 commit comments

Comments
 (0)