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

Side by Side Diff: net/socket/fuzzed_server_socket.cc

Issue 2649983003: A simple fuzzer for HttpServer, with limited coverage of WebSocket. (Closed)
Patch Set: Created 3 years, 11 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 "net/socket/fuzzed_server_socket.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_task_runner_handle.h"
11 #include "net/socket/fuzzed_socket.h"
12
13 namespace net {
14
15 FuzzedServerSocket::FuzzedServerSocket(base::FuzzedDataProvider* data_provider,
16 net::NetLog* net_log)
17 : data_provider_(data_provider),
18 net_log_(net_log),
19 first_accept_(true),
20 listen_called_(false),
21 weak_factory_(this) {}
22
23 FuzzedServerSocket::~FuzzedServerSocket() {}
24
25 int FuzzedServerSocket::Listen(const IPEndPoint& address, int backlog) {
26 DCHECK(!listen_called_);
mmenke 2017/01/24 16:29:16 nit: include base/logging.h
27 listening_on_ = address;
28 listen_called_ = true;
29 return OK;
mmenke 2017/01/24 16:29:16 include net_errors.h
30 }
31
32 int FuzzedServerSocket::GetLocalAddress(IPEndPoint* address) const {
33 *address = listening_on_;
34 return OK;
35 }
36
37 int FuzzedServerSocket::Accept(std::unique_ptr<StreamSocket>* socket,
38 const CompletionCallback& callback) {
39 if (first_accept_) {
40 base::ThreadTaskRunnerHandle::Get()->PostTask(
41 FROM_HERE, base::Bind(&FuzzedServerSocket::DispatchAccept,
42 weak_factory_.GetWeakPtr(), socket, callback));
43 }
44 first_accept_ = false;
45
46 return ERR_IO_PENDING;
mmenke 2017/01/24 16:29:16 Accept can technically succeed synchronously, can'
47 }
48
49 void FuzzedServerSocket::DispatchAccept(std::unique_ptr<StreamSocket>* socket,
50 const CompletionCallback& callback) {
51 std::unique_ptr<FuzzedSocket> connected_socket(
52 base::MakeUnique<FuzzedSocket>(data_provider_, net_log_));
53 // The Connect call should always succeed synchronously, without using the
54 // callback, since connected_socket->set_fuzz_connect_result(true) has not
55 // been called.
56 CHECK_EQ(net::OK, connected_socket->Connect(callback));
57 *socket = std::move(connected_socket);
58 callback.Run(OK);
mmenke 2017/01/24 16:29:16 I guess the test fixture wouldn't exit properly on
59 }
60
61 } // namespace net
OLDNEW
« net/socket/fuzzed_server_socket.h ('K') | « net/socket/fuzzed_server_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698