Skip to content

Commit 61e0e1c

Browse files
committed
Ensure fuzz targets work as expected.
1 parent 5d1bad7 commit 61e0e1c

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

fuzzing/fuzz_http11_request_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ def test_one_input(data):
2020

2121
try:
2222
next(parser)
23-
except StopIteration:
24-
pass # request is available in exc.value
23+
except StopIteration as exc:
24+
assert isinstance(exc.value, Request)
25+
return # input accepted
2526
except (
2627
EOFError, # connection is closed without a full HTTP request
2728
SecurityError, # request exceeds a security limit
2829
ValueError, # request isn't well formatted
2930
):
30-
pass
31+
return # input rejected with a documented exception
32+
33+
raise RuntimeError("parsing didn't complete")
3134

3235

3336
def main():

fuzzing/fuzz_http11_response_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ def test_one_input(data):
2121
)
2222
try:
2323
next(parser)
24-
except StopIteration:
25-
pass # response is available in exc.value
24+
except StopIteration as exc:
25+
assert isinstance(exc.value, Response)
26+
return # input accepted
2627
except (
2728
EOFError, # connection is closed without a full HTTP response
2829
SecurityError, # response exceeds a security limit
2930
LookupError, # response isn't well formatted
3031
ValueError, # response isn't well formatted
3132
):
32-
pass
33+
return # input rejected with a documented exception
34+
35+
raise RuntimeError("parsing didn't complete")
3336

3437

3538
def main():

fuzzing/fuzz_websocket_parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ def test_one_input(data):
2828

2929
try:
3030
next(parser)
31-
except StopIteration:
32-
pass # response is available in exc.value
31+
except StopIteration as exc:
32+
assert isinstance(exc.value, Frame)
33+
return # input accepted
3334
except (
3435
PayloadTooBig, # frame's payload size exceeds ``max_size``
3536
ProtocolError, # frame contains incorrect values
3637
):
37-
pass
38+
return # input rejected with a documented exception
39+
40+
raise RuntimeError("parsing didn't complete")
3841

3942

4043
def main():

0 commit comments

Comments
 (0)