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

Unified Diff: net/tools/dns_fuzz_stub/dns_fuzz_stub.cc

Issue 10441027: Stub binary for fuzzing DNS resolver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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/net.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/dns_fuzz_stub/dns_fuzz_stub.cc
diff --git a/net/tools/dns_fuzz_stub/dns_fuzz_stub.cc b/net/tools/dns_fuzz_stub/dns_fuzz_stub.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f2be09f42d9ef8d882b31cf5d8e003362578d2a6
--- /dev/null
+++ b/net/tools/dns_fuzz_stub/dns_fuzz_stub.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2012 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "base/time.h"
+#include "base/scoped_array.h"
+#include "net/base/address_list.h"
+#include "net/base/dns_util.h"
+#include "net/base/io_buffer.h"
+#include "net/base/ip_endpoint.h"
+#include "net/dns/dns_protocol.h"
+#include "net/dns/dns_query.h"
+#include "net/dns/dns_response.h"
+
+namespace {
+
+int Usage(const char* program_name) {
+ LOG(ERROR) << "Usage: " << program_name << " test_case_filename";
+ return 1;
+}
+
+int InvalidTestCase(const char* program_name) {
+ LOG(ERROR) << "Test case format invalid";
+ return 2;
+}
+
+// TODO(ttuttle): This should read from the file, probably in JSON.
+bool ReadTestCase(const char* filename,
+ uint16_t* id, std::string* qname, uint16_t* qtype,
+ size_t* resp_len, char** resp_buf) {
szym 2012/05/31 21:43:10 Consider using std::vector<char>* instead of char*
Deprecated (see juliatuttle) 2012/05/31 22:11:56 Done.
+ static const unsigned char resp[] = {
+ 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x61, 0x00, 0x00, 0x01, 0x00, 0x01,
+ 0x01, 0x61, 0x00, 0x00, 0x01, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0xff, 0x00, 0x04, 0x0a, 0x0a, 0x0a, 0x0a };
+
+ *id = 0x0000;
+ *qname = "a";
+ *qtype = 0x0001;
+
+ *resp_len = sizeof(resp);
+ *resp_buf = new char[arraysize(resp)];
+ memcpy(*resp_buf, resp, sizeof(resp));
szym 2012/05/31 21:43:10 If you go with std::vector, this can be done with
Deprecated (see juliatuttle) 2012/05/31 22:11:56 Done.
+
+ return true;
+}
+
+}
+
+int main(int argc, char** argv) {
+ if (argc != 2)
+ return Usage(argv[0]);
+
+ const char* filename = argv[1];
+
+ LOG(INFO) << "Test case: " << filename;
+
+ uint16_t id;
+ std::string qname_dotted;
+ uint16_t qtype;
+ size_t resp_len;
+ scoped_array<char> resp;
+ char* resp_buf;
+
+ if (!ReadTestCase(filename,
+ &id, &qname_dotted, &qtype,
+ &resp_len, &resp_buf)) {
+ return InvalidTestCase(argv[0]);
+ }
+
+ resp.reset(resp_buf);
szym 2012/05/31 21:43:10 It's probably cleaner to pass &resp (scoped_array*
Deprecated (see juliatuttle) 2012/05/31 22:11:56 Done.
+
+ LOG(INFO) << "Query: id=" << id
+ << " qname=" << qname_dotted
+ << " qtype=" << qtype;
+ LOG(INFO) << "Response: " << resp_len << " bytes";
+
+ std::string qname;
+ if (!net::DNSDomainFromDot(qname_dotted, &qname)) {
+ LOG(ERROR) << "DNSDomainFromDot(" << qname_dotted << ") failed.";
+ return 3;
+ }
+
+ net::DnsQuery query(id, qname, qtype);
+ net::DnsResponse response;
+ memcpy(response.io_buffer()->data(), resp_buf, resp_len);
Deprecated (see juliatuttle) 2012/05/31 22:11:56 std::copy! :D Also, implicit conversion from an a
+
+ if (!response.InitParse(resp_len, query)) {
+ LOG(INFO) << "InitParse failed.";
+ return 0;
+ }
+
+ net::AddressList address_list;
+ base::TimeDelta ttl;
+ net::DnsResponse::Result result = response.ParseToAddressList(
+ &address_list, &ttl);
+ if (result != net::DnsResponse::DNS_SUCCESS) {
+ LOG(INFO) << "ParseToAddressList failed: " << result;
+ return 0;
+ }
+
+ LOG(INFO) << "Address List:";
+ for (unsigned int i = 0; i < address_list.size(); i++) {
+ LOG(INFO) << "\t" << address_list[i].ToString();
+ }
+ LOG(INFO) << "TTL: " << ttl.InSeconds() << " seconds";
+
+ return 0;
+}
+
« no previous file with comments | « net/net.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698