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

Side by Side 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, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/net.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #include "base/time.h"
10 #include "base/scoped_array.h"
11 #include "net/base/address_list.h"
12 #include "net/base/dns_util.h"
13 #include "net/base/io_buffer.h"
14 #include "net/base/ip_endpoint.h"
15 #include "net/dns/dns_protocol.h"
16 #include "net/dns/dns_query.h"
17 #include "net/dns/dns_response.h"
18
19 namespace {
20
21 int Usage(const char* program_name) {
22 LOG(ERROR) << "Usage: " << program_name << " test_case_filename";
23 return 1;
24 }
25
26 int InvalidTestCase(const char* program_name) {
27 LOG(ERROR) << "Test case format invalid";
28 return 2;
29 }
30
31 // TODO(ttuttle): This should read from the file, probably in JSON.
32 bool ReadTestCase(const char* filename,
33 uint16_t* id, std::string* qname, uint16_t* qtype,
34 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.
35 static const unsigned char resp[] = {
36 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
37 0x01, 0x61, 0x00, 0x00, 0x01, 0x00, 0x01,
38 0x01, 0x61, 0x00, 0x00, 0x01, 0x00, 0x01,
39 0x00, 0x00, 0x00, 0xff, 0x00, 0x04, 0x0a, 0x0a, 0x0a, 0x0a };
40
41 *id = 0x0000;
42 *qname = "a";
43 *qtype = 0x0001;
44
45 *resp_len = sizeof(resp);
46 *resp_buf = new char[arraysize(resp)];
47 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.
48
49 return true;
50 }
51
52 }
53
54 int main(int argc, char** argv) {
55 if (argc != 2)
56 return Usage(argv[0]);
57
58 const char* filename = argv[1];
59
60 LOG(INFO) << "Test case: " << filename;
61
62 uint16_t id;
63 std::string qname_dotted;
64 uint16_t qtype;
65 size_t resp_len;
66 scoped_array<char> resp;
67 char* resp_buf;
68
69 if (!ReadTestCase(filename,
70 &id, &qname_dotted, &qtype,
71 &resp_len, &resp_buf)) {
72 return InvalidTestCase(argv[0]);
73 }
74
75 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.
76
77 LOG(INFO) << "Query: id=" << id
78 << " qname=" << qname_dotted
79 << " qtype=" << qtype;
80 LOG(INFO) << "Response: " << resp_len << " bytes";
81
82 std::string qname;
83 if (!net::DNSDomainFromDot(qname_dotted, &qname)) {
84 LOG(ERROR) << "DNSDomainFromDot(" << qname_dotted << ") failed.";
85 return 3;
86 }
87
88 net::DnsQuery query(id, qname, qtype);
89 net::DnsResponse response;
90 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
91
92 if (!response.InitParse(resp_len, query)) {
93 LOG(INFO) << "InitParse failed.";
94 return 0;
95 }
96
97 net::AddressList address_list;
98 base::TimeDelta ttl;
99 net::DnsResponse::Result result = response.ParseToAddressList(
100 &address_list, &ttl);
101 if (result != net::DnsResponse::DNS_SUCCESS) {
102 LOG(INFO) << "ParseToAddressList failed: " << result;
103 return 0;
104 }
105
106 LOG(INFO) << "Address List:";
107 for (unsigned int i = 0; i < address_list.size(); i++) {
108 LOG(INFO) << "\t" << address_list[i].ToString();
109 }
110 LOG(INFO) << "TTL: " << ttl.InSeconds() << " seconds";
111
112 return 0;
113 }
114
OLDNEW
« 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