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

Unified Diff: net/socket/fuzzed_server_socket.cc

Issue 2649983003: A simple fuzzer for HttpServer, with limited coverage of WebSocket. (Closed)
Patch Set: Rebased, looked like doing it automatically failed 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/socket/fuzzed_server_socket.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/fuzzed_server_socket.cc
diff --git a/net/socket/fuzzed_server_socket.cc b/net/socket/fuzzed_server_socket.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6f3c08ecd4165477a0eb4c08c9f5ec63b6b13e2b
--- /dev/null
+++ b/net/socket/fuzzed_server_socket.cc
@@ -0,0 +1,61 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/socket/fuzzed_server_socket.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/memory/ptr_util.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "net/socket/fuzzed_socket.h"
+
+namespace net {
+
+FuzzedServerSocket::FuzzedServerSocket(base::FuzzedDataProvider* data_provider,
+ net::NetLog* net_log)
+ : data_provider_(data_provider),
+ net_log_(net_log),
+ first_accept_(true),
+ listen_called_(false),
+ weak_factory_(this) {}
+
+FuzzedServerSocket::~FuzzedServerSocket() {}
+
+int FuzzedServerSocket::Listen(const IPEndPoint& address, int backlog) {
+ DCHECK(!listen_called_);
+ listening_on_ = address;
+ listen_called_ = true;
+ return OK;
+}
+
+int FuzzedServerSocket::GetLocalAddress(IPEndPoint* address) const {
+ *address = listening_on_;
+ return OK;
+}
+
+int FuzzedServerSocket::Accept(std::unique_ptr<StreamSocket>* socket,
+ const CompletionCallback& callback) {
+ if (first_accept_) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&FuzzedServerSocket::DispatchAccept,
+ weak_factory_.GetWeakPtr(), socket, callback));
+ }
+ first_accept_ = false;
+
+ return ERR_IO_PENDING;
+}
+
+void FuzzedServerSocket::DispatchAccept(std::unique_ptr<StreamSocket>* socket,
+ const CompletionCallback& callback) {
+ std::unique_ptr<FuzzedSocket> connected_socket(
+ base::MakeUnique<FuzzedSocket>(data_provider_, net_log_));
+ // The Connect call should always succeed synchronously, without using the
+ // callback, since connected_socket->set_fuzz_connect_result(true) has not
+ // been called.
+ CHECK_EQ(net::OK, connected_socket->Connect(callback));
+ *socket = std::move(connected_socket);
+ callback.Run(OK);
+}
+
+} // namespace net
« no previous file with comments | « net/socket/fuzzed_server_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698