Skip to content

Commit

Permalink
Ensure fuzz targets work as expected.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Aug 24, 2022
1 parent 5d1bad7 commit 1726dba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions fuzzing/fuzz_http11_request_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ def test_one_input(data):

try:
next(parser)
except StopIteration:
pass # request is available in exc.value
except StopIteration as exc:
assert isinstance(exc.value, Request)
return
except (
EOFError, # connection is closed without a full HTTP request
SecurityError, # request exceeds a security limit
ValueError, # request isn't well formatted
):
pass

raise RuntimeError("parsing didn't complete")


def main():
atheris.Setup(sys.argv, test_one_input)
Expand Down
7 changes: 5 additions & 2 deletions fuzzing/fuzz_http11_response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def test_one_input(data):
)
try:
next(parser)
except StopIteration:
pass # response is available in exc.value
except StopIteration as exc:
assert isinstance(exc.value, Response)
return
except (
EOFError, # connection is closed without a full HTTP response
SecurityError, # response exceeds a security limit
Expand All @@ -31,6 +32,8 @@ def test_one_input(data):
):
pass

raise RuntimeError("parsing didn't complete")


def main():
atheris.Setup(sys.argv, test_one_input)
Expand Down
7 changes: 5 additions & 2 deletions fuzzing/fuzz_websocket_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ def test_one_input(data):

try:
next(parser)
except StopIteration:
pass # response is available in exc.value
except StopIteration as exc:
assert isinstance(exc.value, Frame)
return
except (
PayloadTooBig, # frame's payload size exceeds ``max_size``
ProtocolError, # frame contains incorrect values
):
pass

raise RuntimeError("parsing didn't complete")


def main():
atheris.Setup(sys.argv, test_one_input)
Expand Down

0 comments on commit 1726dba

Please sign in to comment.