Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: net/server/http_server_fuzzer.cc

Issue 2649983003: A simple fuzzer for HttpServer, with limited coverage of WebSocket. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/ptr_util.h"
6 #include "base/test/fuzzed_data_provider.h"
7 #include "net/base/test_completion_callback.h"
8 #include "net/log/test_net_log.h"
9 #include "net/server/http_server.h"
10 #include "net/socket/fuzzed_server_socket.h"
11
12 namespace {
13
14 class WaitTillHttpCloseDelegate : public net::HttpServer::Delegate {
15 public:
16 WaitTillHttpCloseDelegate(base::FuzzedDataProvider* data_provider,
17 const net::CompletionCallback& callback)
18 : server_(nullptr), data_provider_(data_provider), callback_(callback) {
19 should_accept_webp_ = data_provider_->ConsumeBool();
mmenke 2017/01/24 16:29:16 This variable name is confusing. webp is the name
Maks Orlovich 2017/01/24 18:34:18 Err, yeah. My past life shining through.
20 }
21
22 void set_server(net::HttpServer* server) { server_ = server; }
23
24 void OnConnect(int connection_id) override {}
mmenke 2017/01/24 16:29:16 Randomly close the socket or not here?
Maks Orlovich 2017/01/25 14:54:37 Done.
25 void OnHttpRequest(int connection_id,
26 const net::HttpServerRequestInfo& info) override {}
mmenke 2017/01/24 16:29:16 Should we randomly write data or close the connect
mmenke 2017/01/24 19:43:58 (Also, may want to do this multiple times, and syn
Maks Orlovich 2017/01/25 14:54:37 Done.
27
28 void OnWebSocketRequest(int connection_id,
29 const net::HttpServerRequestInfo& info) override {
30 // Randomize whether the delegate accepts web socket or not, to cover both
31 // options.
32 if (should_accept_webp_)
33 server_->AcceptWebSocket(connection_id, info);
34 }
35
36 void OnWebSocketMessage(int connection_id, const std::string& data) override {
mmenke 2017/01/24 16:29:16 Should we randomly write data or close the connect
Maks Orlovich 2017/01/25 14:54:37 Done.
37 }
38 void OnClose(int connection_id) override { callback_.Run(net::OK); }
mmenke 2017/01/24 19:43:58 Why is the socket guaranteed to be closed?
39
40 private:
41 net::HttpServer* server_;
42 base::FuzzedDataProvider* data_provider_;
mmenke 2017/01/24 16:29:16 nit: base::FuzzedDataProvider* const (Meaning th
Maks Orlovich 2017/01/24 18:34:18 Done.
43 net::CompletionCallback callback_;
44 bool should_accept_webp_;
mmenke 2017/01/24 16:29:16 add this to the initializer list and make it a con
mmenke 2017/01/24 16:29:16 DISALLOW_COPY_AND_ASSIGN + include base/macros.h
Maks Orlovich 2017/01/24 18:34:18 Done.
45 };
46
47 } // namespace
48
49 // Fuzzer for HttpServer
50 //
51 // |data| is used to create a FuzzedServerSocket.
52 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
53 net::BoundTestNetLog bound_test_net_log;
mmenke 2017/01/24 16:29:16 Should just be using TestNetLog (Then don't need t
Maks Orlovich 2017/01/25 14:54:37 Done.
54 base::FuzzedDataProvider data_provider(data, size);
55
56 std::unique_ptr<net::ServerSocket> server_socket(
57 base::MakeUnique<net::FuzzedServerSocket>(
58 &data_provider, bound_test_net_log.bound().net_log()));
59 CHECK_EQ(net::OK,
mmenke 2017/01/24 16:29:16 include net/base/net_errors.h and base/logging.h
Maks Orlovich 2017/01/25 14:54:37 Done.
60 server_socket->ListenWithAddressAndPort("127.0.0.1", 80, 5));
61
62 net::TestCompletionCallback callback; // provides the message loop
mmenke 2017/01/24 16:29:16 The comment isn't correct. It can spin the messag
Maks Orlovich 2017/01/25 14:54:37 Spinning is what I meant; the sloppy comment is be
63 WaitTillHttpCloseDelegate delegate(&data_provider, callback.callback());
64 net::HttpServer server(std::move(server_socket), &delegate);
65 delegate.set_server(&server);
66 CHECK_EQ(net::OK, callback.WaitForResult());
mmenke 2017/01/24 16:29:16 Why check the result? Also, I don't think we real
Maks Orlovich 2017/01/25 14:54:37 Switched to RunLoop --- which made the result issu
67 return 0;
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698