Debian Codegraph @

fuzzing/fuzz_http11_request_parser.py

raw
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 parser = Request.parse(
18 reader.read_line,
19 )
20
21 try:
22 next(parser)
23 except StopIteration as exc:
24 assert isinstance(exc.value, Request)
25 return # input accepted
26 except (
27 EOFError, # connection is closed without a full HTTP request
28 SecurityError, # request exceeds a security limit
29 ValueError, # request isn't well formatted
30 ):
31 return # input rejected with a documented exception
32
33 raise RuntimeError("parsing didn't complete")
34
35
36 def main():
37 atheris.Setup(sys.argv, test_one_input)
38 atheris.Fuzz()
39
40
41 if __name__ == "__main__":
42 main()