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

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 "net/base/address_list.h"
11 #include "net/base/dns_util.h"
12 #include "net/base/io_buffer.h"
13 #include "net/base/ip_endpoint.h"
14 #include "net/dns/dns_protocol.h"
15 #include "net/dns/dns_query.h"
16 #include "net/dns/dns_response.h"
17
18 namespace {
19
20 int Usage(const char* program_name) {
21 fprintf(stderr, "Usage: %s test_case_filename\n", program_name);
22 return 1;
23 }
24
25 int InvalidTestCase(const char* program_name) {
26 fprintf(stderr, "%s: Test case format invalid\n", program_name);
27 return 2;
28 }
29
30 // TODO(ttuttle): This should read from the file, probably in JSON.
31 bool ReadTestCase(const char* filename,
32 uint16_t* id, std::string* qname, uint16_t* qtype,
33 size_t* resp_len, char** resp_buf) {
34 static const unsigned char resp[] = {
35 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
36 0x01, 0x61, 0x00, 0x00, 0x01, 0x00, 0x01,
37 0x01, 0x61, 0x00, 0x00, 0x01, 0x00, 0x01,
38 0x00, 0x00, 0x00, 0xff, 0x00, 0x04, 0x0a, 0x0a, 0x0a, 0x0a };
39
40 *id = 0x0000;
41 *qname = "a";
42 *qtype = 0x0001;
43
44 *resp_len = arraysize(resp);
szym 2012/05/31 16:46:11 This should actually be sizeof :) memcpy expects t
Deprecated (see juliatuttle) 2012/05/31 16:49:43 Gah, okay, got it.
45 *resp_buf = new char[arraysize(resp)];
46 memcpy(*resp_buf, resp, sizeof(resp));
47
48 return true;
49 }
50
51 }
52
53 int main(int argc, char** argv) {
54 if (argc != 2)
55 return Usage(argv[0]);
56
57 const char* filename = argv[1];
58
59 printf("Test case: %s\n", filename);
60
61 uint16_t id;
62 std::string qname_dotted;
63 uint16_t qtype;
64 size_t resp_len;
65 char* resp_buf;
66
67 if (!ReadTestCase(filename,
68 &id, &qname_dotted, &qtype,
69 &resp_len, &resp_buf)) {
70 return InvalidTestCase(argv[0]);
71 }
72
73 printf("Query: id=%hu qname=%s qtype=%hu\n", id, qname_dotted.c_str(), qtype);
74 printf("Response: %d bytes\n", (int)resp_len);
75
76 std::string qname;
77 if (!net::DNSDomainFromDot(qname_dotted, &qname)) {
78 printf("%s: DNSDomainFromDot(%s) failed.\n", argv[0], qname_dotted.c_str());
79 return 3;
80 }
81
82 net::DnsQuery query(id, qname, qtype);
83 net::DnsResponse response;
84 memcpy(response.io_buffer()->data(), resp_buf, resp_len);
85
86 if (!response.InitParse(resp_len, query)) {
87 printf("InitParse failed.\n");
88 return 0;
89 }
90
91 net::AddressList address_list;
92 base::TimeDelta ttl;
93 net::DnsResponse::Result result = response.ParseToAddressList(
94 &address_list, &ttl);
95 if (result != net::DnsResponse::DNS_SUCCESS) {
96 printf("ParseToAddressList failed: %d\n", result);
97 return 0;
98 }
99
100 printf("Address List:\n");
101 for (unsigned int i = 0; i < address_list.size(); i++) {
102 std::string address_str = address_list[i].ToString();
103 printf("\t%s\n", address_str.c_str());
104 }
105 printf("TTL: %d seconds\n", static_cast<int>(ttl.InSeconds()));
106
107 return 0;
108 }
109
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