Skip to content

Commit fd17f46

Browse files
committed
Add OSS-Fuzz fuzz targets (experimental).
1 parent cfa70ca commit fd17f46

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

fuzzing/fuzz_http11_request_parser.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import sys
2+
3+
import atheris
4+
5+
6+
with atheris.instrument_imports():
7+
from websockets.exceptions import SecurityError
8+
from websockets.http11 import Request
9+
from websockets.streams import StreamReader
10+
11+
12+
def test_one_input(data):
13+
reader = StreamReader()
14+
reader.feed_data(data)
15+
reader.feed_eof()
16+
17+
try:
18+
Request.parse(
19+
reader.read_line,
20+
)
21+
except (
22+
EOFError, # connection is closed without a full HTTP request
23+
SecurityError, # request exceeds a security limit
24+
ValueError, # request isn't well formatted
25+
):
26+
pass
27+
28+
29+
def main():
30+
atheris.Setup(sys.argv, test_one_input)
31+
atheris.Fuzz()
32+
33+
34+
if __name__ == "__main__":
35+
main()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import sys
2+
3+
import atheris
4+
5+
6+
with atheris.instrument_imports():
7+
from websockets.exceptions import SecurityError
8+
from websockets.http11 import Response
9+
from websockets.streams import StreamReader
10+
11+
12+
def test_one_input(data):
13+
reader = StreamReader()
14+
reader.feed_data(data)
15+
reader.feed_eof()
16+
17+
try:
18+
Response.parse(
19+
reader.read_line,
20+
reader.read_exact,
21+
reader.read_to_eof,
22+
)
23+
except (
24+
EOFError, # connection is closed without a full HTTP response.
25+
SecurityError, # response exceeds a security limit.
26+
LookupError, # response isn't well formatted.
27+
ValueError, # response isn't well formatted.
28+
):
29+
pass
30+
31+
32+
def main():
33+
atheris.Setup(sys.argv, test_one_input)
34+
atheris.Fuzz()
35+
36+
37+
if __name__ == "__main__":
38+
main()

0 commit comments

Comments
 (0)