/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 | 34.5k | { |
18 | 34.5k | try |
19 | 34.5k | { |
20 | 34.5k | func(); |
21 | 34.5k | } |
22 | 34.5k | catch (const std::exception&) |
23 | 34.5k | { |
24 | 26.2k | } |
25 | 34.5k | } HTTPParse.cpp:void catchExceptions<LLVMFuzzerTestOneInput::$_0>(LLVMFuzzerTestOneInput::$_0 const&) Line | Count | Source | 17 | 8.64k | { | 18 | 8.64k | try | 19 | 8.64k | { | 20 | 8.64k | func(); | 21 | 8.64k | } | 22 | 8.64k | catch (const std::exception&) | 23 | 8.64k | { | 24 | 2.66k | } | 25 | 8.64k | } |
HTTPParse.cpp:void catchExceptions<LLVMFuzzerTestOneInput::$_1>(LLVMFuzzerTestOneInput::$_1 const&) Line | Count | Source | 17 | 8.64k | { | 18 | 8.64k | try | 19 | 8.64k | { | 20 | 8.64k | func(); | 21 | 8.64k | } | 22 | 8.64k | catch (const std::exception&) | 23 | 8.64k | { | 24 | 7.23k | } | 25 | 8.64k | } |
HTTPParse.cpp:void catchExceptions<LLVMFuzzerTestOneInput::$_2>(LLVMFuzzerTestOneInput::$_2 const&) Line | Count | Source | 17 | 8.64k | { | 18 | 8.64k | try | 19 | 8.64k | { | 20 | 8.64k | func(); | 21 | 8.64k | } | 22 | 8.64k | catch (const std::exception&) | 23 | 8.64k | { | 24 | 7.74k | } | 25 | 8.64k | } |
HTTPParse.cpp:void catchExceptions<LLVMFuzzerTestOneInput::$_3>(LLVMFuzzerTestOneInput::$_3 const&) Line | Count | Source | 17 | 8.64k | { | 18 | 8.64k | try | 19 | 8.64k | { | 20 | 8.64k | func(); | 21 | 8.64k | } | 22 | 8.64k | catch (const std::exception&) | 23 | 8.64k | { | 24 | 8.62k | } | 25 | 8.64k | } |
|
26 | | |
27 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
28 | 8.64k | { |
29 | 8.64k | NullOutputStream null; |
30 | | |
31 | | // HTTPRequest parsing |
32 | 8.64k | catchExceptions( |
33 | 8.64k | [&] |
34 | 8.64k | { |
35 | 8.64k | MemoryInputStream stream(reinterpret_cast<const char*>(data), size); |
36 | 8.64k | HTTPRequest request; |
37 | 8.64k | request.read(stream); |
38 | 8.64k | request.write(null); |
39 | | |
40 | 8.64k | HTTPCredentials creds; |
41 | 8.64k | creds.fromURI(URI(request.getURI())); |
42 | 8.64k | creds.updateAuthInfo(request); |
43 | 8.64k | creds.updateProxyAuthInfo(request); |
44 | 8.64k | }); |
45 | | |
46 | | // HTTPResponse parsing |
47 | 8.64k | catchExceptions( |
48 | 8.64k | [&] |
49 | 8.64k | { |
50 | 8.64k | MemoryInputStream stream(reinterpret_cast<const char*>(data), size); |
51 | 8.64k | HTTPResponse response; |
52 | 8.64k | response.read(stream); |
53 | 8.64k | response.write(null); |
54 | | |
55 | 8.64k | HTTPRequest request(HTTPRequest::HTTP_GET, "/"); |
56 | 8.64k | request.setHost(DNS::encodeIDN(DNS::decodeIDN(response.get(HTTPRequest::HOST)))); |
57 | | |
58 | 8.64k | HTTPCredentials creds; |
59 | 8.64k | creds.authenticate(request, response); |
60 | 8.64k | creds.proxyAuthenticate(request, response); |
61 | 8.64k | }); |
62 | | |
63 | | // OAuth10Credentials |
64 | 8.64k | catchExceptions( |
65 | 8.64k | [&] |
66 | 8.64k | { |
67 | 8.64k | MemoryInputStream stream(reinterpret_cast<const char*>(data), size); |
68 | 8.64k | HTTPRequest request; |
69 | 8.64k | request.read(stream); |
70 | | |
71 | 8.64k | EscapeHTMLOutputStream htmlStream(null); |
72 | 8.64k | HTMLForm form(request, stream); |
73 | 8.64k | form.prepareSubmit(request); |
74 | 8.64k | form.write(htmlStream); |
75 | | |
76 | 8.64k | OAuth10Credentials oauth10(request); |
77 | 8.64k | oauth10.verify(request, URI(request.getURI()), form); |
78 | 8.64k | oauth10.authenticate(request, URI(request.getURI()), form, |
79 | 8.64k | request.hasToken("X-Method", "Plain") ? OAuth10Credentials::SIGN_PLAINTEXT |
80 | 8.64k | : OAuth10Credentials::SIGN_HMAC_SHA1); |
81 | 8.64k | }); |
82 | | |
83 | | // OAuth20Credentials |
84 | 8.64k | catchExceptions( |
85 | 8.64k | [&] |
86 | 8.64k | { |
87 | 8.64k | MemoryInputStream stream(reinterpret_cast<const char*>(data), size); |
88 | 8.64k | HTTPRequest request; |
89 | 8.64k | request.read(stream); |
90 | | |
91 | 8.64k | OAuth20Credentials oauth20(request); |
92 | 8.64k | oauth20.authenticate(request); |
93 | 8.64k | }); |
94 | | |
95 | 8.64k | return 0; |
96 | 8.64k | } |