From 61e0e1c10f9895a15b34f0d43f160c6b4861e18b Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Wed, 24 Aug 2022 08:04:54 +0200 Subject: [PATCH] Ensure fuzz targets work as expected. --- fuzzing/fuzz_http11_request_parser.py | 9 ++++++--- fuzzing/fuzz_http11_response_parser.py | 9 ++++++--- fuzzing/fuzz_websocket_parser.py | 9 ++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fuzzing/fuzz_http11_request_parser.py b/fuzzing/fuzz_http11_request_parser.py index 148785385..59e0cea0f 100644 --- a/fuzzing/fuzz_http11_request_parser.py +++ b/fuzzing/fuzz_http11_request_parser.py @@ -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(): diff --git a/fuzzing/fuzz_http11_response_parser.py b/fuzzing/fuzz_http11_response_parser.py index 0f783f6fd..6906720a4 100644 --- a/fuzzing/fuzz_http11_response_parser.py +++ b/fuzzing/fuzz_http11_response_parser.py @@ -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(): diff --git a/fuzzing/fuzz_websocket_parser.py b/fuzzing/fuzz_websocket_parser.py index 7569d0b61..ab9c1dd2e 100644 --- a/fuzzing/fuzz_websocket_parser.py +++ b/fuzzing/fuzz_websocket_parser.py @@ -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():