/src/poco/Net/fuzzing/HTTPParse.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include "Poco/MemoryStream.h" |
2 | | #include "Poco/Net/EscapeHTMLStream.h" |
3 | | #include "Poco/Net/HTMLForm.h" |
4 | | #include "Poco/Net/HTTPCredentials.h" |
5 | | #include "Poco/Net/HTTPRequest.h" |
6 | | #include "Poco/Net/HTTPResponse.h" |
7 | | #include "Poco/Net/OAuth10Credentials.h" |
8 | | #include "Poco/Net/OAuth20Credentials.h" |
9 | | #include "Poco/Net/DNS.h" |
10 | | #include "Poco/NullStream.h" |
11 | | |
12 | | using namespace Poco; |
13 | | using namespace Poco::Net; |
14 | | |
15 | | template <class F> |
16 | | void catchExceptions(const F& func) |
17 | 43.2k | { |
18 | 43.2k | try |
19 | 43.2k | { |
20 | 43.2k | func(); |
21 | 43.2k | } |
22 | 43.2k | catch (const std::exception&) |
23 | 43.2k | { |
24 | 32.8k | } |
25 | 43.2k | } HTTPParse.cpp:void catchExceptions<LLVMFuzzerTestOneInput::$_0>(LLVMFuzzerTestOneInput::$_0 const&) Line | Count | Source | 17 | 10.8k | { | 18 | 10.8k | try | 19 | 10.8k | { | 20 | 10.8k | func(); | 21 | 10.8k | } | 22 | 10.8k | catch (const std::exception&) | 23 | 10.8k | { | 24 | 3.27k | } | 25 | 10.8k | } |
HTTPParse.cpp:void catchExceptions<LLVMFuzzerTestOneInput::$_1>(LLVMFuzzerTestOneInput::$_1 const&) Line | Count | Source | 17 | 10.8k | { | 18 | 10.8k | try | 19 | 10.8k | { | 20 | 10.8k | func(); | 21 | 10.8k | } | 22 | 10.8k | catch (const std::exception&) | 23 | 10.8k | { | 24 | 9.08k | } | 25 | 10.8k | } |
HTTPParse.cpp:void catchExceptions<LLVMFuzzerTestOneInput::$_2>(LLVMFuzzerTestOneInput::$_2 const&) Line | Count | Source | 17 | 10.8k | { | 18 | 10.8k | try | 19 | 10.8k | { | 20 | 10.8k | func(); | 21 | 10.8k | } | 22 | 10.8k | catch (const std::exception&) | 23 | 10.8k | { | 24 | 9.71k | } | 25 | 10.8k | } |
HTTPParse.cpp:void catchExceptions<LLVMFuzzerTestOneInput::$_3>(LLVMFuzzerTestOneInput::$_3 const&) Line | Count | Source | 17 | 10.8k | { | 18 | 10.8k | try | 19 | 10.8k | { | 20 | 10.8k | func(); | 21 | 10.8k | } | 22 | 10.8k | catch (const std::exception&) | 23 | 10.8k | { | 24 | 10.8k | } | 25 | 10.8k | } |
|
26 | | |
27 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
28 | 10.8k | { |
29 | 10.8k | NullOutputStream null; |
30 | | |
31 | | // HTTPRequest parsing |
32 | 10.8k | catchExceptions( |
33 | 10.8k | [&] |
34 | 10.8k | { |
35 | 10.8k | MemoryInputStream stream(reinterpret_cast<const char*>(data), size); |
36 | 10.8k | HTTPRequest request; |
37 | 10.8k | request.read(stream); |
38 | 10.8k | request.write(null); |
39 | | |
40 | 10.8k | HTTPCredentials creds; |
41 | 10.8k | creds.fromURI(URI(request.getURI())); |
42 | 10.8k | creds.updateAuthInfo(request); |
43 | 10.8k | creds.updateProxyAuthInfo(request); |
44 | 10.8k | }); |
45 | | |
46 | | // HTTPResponse parsing |
47 | 10.8k | catchExceptions( |
48 | 10.8k | [&] |
49 | 10.8k | { |
50 | 10.8k | MemoryInputStream stream(reinterpret_cast<const char*>(data), size); |
51 | 10.8k | HTTPResponse response; |
52 | 10.8k | response.read(stream); |
53 | 10.8k | response.write(null); |
54 | | |
55 | 10.8k | HTTPRequest request(HTTPRequest::HTTP_GET, "/"); |
56 | 10.8k | request.setHost(DNS::encodeIDN(DNS::decodeIDN(response.get(HTTPRequest::HOST)))); |
57 | | |
58 | 10.8k | HTTPCredentials creds; |
59 | 10.8k | creds.authenticate(request, response); |
60 | 10.8k | creds.proxyAuthenticate(request, response); |
61 | 10.8k | }); |
62 | | |
63 | | // OAuth10Credentials |
64 | 10.8k | catchExceptions( |
65 | 10.8k | [&] |
66 | 10.8k | { |
67 | 10.8k | MemoryInputStream stream(reinterpret_cast<const char*>(data), size); |
68 | 10.8k | HTTPRequest request; |
69 | 10.8k | request.read(stream); |
70 | | |
71 | 10.8k | EscapeHTMLOutputStream htmlStream(null); |
72 | 10.8k | HTMLForm form(request, stream); |
73 | 10.8k | form.prepareSubmit(request); |
74 | 10.8k | form.write(htmlStream); |
75 | | |
76 | 10.8k | OAuth10Credentials oauth10(request); |
77 | 10.8k | oauth10.verify(request, URI(request.getURI()), form); |
78 | 10.8k | oauth10.authenticate(request, URI(request.getURI()), form, |
79 | 10.8k | request.hasToken("X-Method", "Plain") ? OAuth10Credentials::SIGN_PLAINTEXT |
80 | 10.8k | : OAuth10Credentials::SIGN_HMAC_SHA1); |
81 | 10.8k | }); |
82 | | |
83 | | // OAuth20Credentials |
84 | 10.8k | catchExceptions( |
85 | 10.8k | [&] |
86 | 10.8k | { |
87 | 10.8k | MemoryInputStream stream(reinterpret_cast<const char*>(data), size); |
88 | 10.8k | HTTPRequest request; |
89 | 10.8k | request.read(stream); |
90 | | |
91 | 10.8k | OAuth20Credentials oauth20(request); |
92 | 10.8k | oauth20.authenticate(request); |
93 | 10.8k | }); |
94 | | |
95 | 10.8k | return 0; |
96 | 10.8k | } |