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 61e0e1c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 6 additions & 3 deletions fuzzing/fuzz_http11_request_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ 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 # input accepted
except (
EOFError, # connection is closed without a full HTTP request
SecurityError, # request exceeds a security limit
ValueError, # request isn't well formatted
):
pass
return # input rejected with a documented exception

raise RuntimeError("parsing didn't complete")


def main():
Expand Down
9 changes: 6 additions & 3 deletions fuzzing/fuzz_http11_response_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ 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 # input accepted
except (
EOFError, # connection is closed without a full HTTP response
SecurityError, # response exceeds a security limit
LookupError, # response isn't well formatted
ValueError, # response isn't well formatted
):
pass
return # input rejected with a documented exception

raise RuntimeError("parsing didn't complete")


def main():
Expand Down
9 changes: 6 additions & 3 deletions fuzzing/fuzz_websocket_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ 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 # input accepted
except (
PayloadTooBig, # frame's payload size exceeds ``max_size``
ProtocolError, # frame contains incorrect values
):
pass
return # input rejected with a documented exception

raise RuntimeError("parsing didn't complete")


def main():
Expand Down

0 comments on commit 61e0e1c

Please sign in to comment.