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

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: Fix szym's comments 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 unified diff | Download patch | Annotate | Revision Log
« net/net.gyp ('K') | « 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 static int Usage(const char* program_name) {
cbentzel 2012/05/25 01:53:55 I don't think there's any hard rules against funct
Deprecated (see juliatuttle) 2012/05/30 22:23:40 Done.
19 fprintf(stderr, "Usage: %s test_case_filename\n", program_name);
20 return 1;
21 }
22
23 static int InvalidTestCase(const char* program_name) {
24 fprintf(stderr, "%s: Test case format invalid\n", program_name);
25 return 2;
26 }
27
28 int main(int argc, char** argv) {
29 if (argc != 2)
30 return Usage(argv[0]);
31
32 const char* filename = argv[1];
33 FILE* file = fopen(filename, "r");
34 if (!file) {
35 perror("open");
36 return Usage(argv[0]);
37 }
38
39 uint16_t id;
40 char qname_dotted[net::dns_protocol::kMaxNameLength];
41 uint16_t qtype;
42
43 // You can overflow domain. We don't really care -- this is a test program
44 // that will always be run under ASAN, and will not ship as part of Chrome.
45 if (fscanf(file, "%hu %s %hu\n", &id, qname_dotted, &qtype) < 3) {
cbentzel 2012/05/25 01:53:55 I don't understand why we don't care about overflo
46 return InvalidTestCase(argv[0]);
47 }
48
49 printf("Query: id=%hu name=%s type=%hu\n", id, qname_dotted, qtype);
50
51 unsigned int response_len;
52 if (fscanf(file, "%d ", &response_len) < 1) {
53 return InvalidTestCase(argv[0]);
54 }
55 char* response_buf = new char[response_len];
56 for (unsigned int i = 0; i < response_len; i++) {
57 if (fscanf(file, "%02hhx ", &response_buf[i]) < 1) {
58 return InvalidTestCase(argv[0]);
59 }
60 }
61
62 printf("Response: %u bytes\n", response_len);
63
64 std::string qname;
65 if (!net::DNSDomainFromDot(qname_dotted, &qname)) {
66 printf("%s: DNSDomainFromDot(%s) failed.\n", argv[0], qname_dotted);
67 return 3;
68 }
69
70 net::DnsQuery query(id, qname, qtype);
71 net::DnsResponse response;
72 memcpy(response.io_buffer()->data(), response_buf, response_len);
73
74 if (!response.InitParse(response_len, query)) {
75 printf("InitParse failed.\n");
76 return 0;
77 }
78
79 net::AddressList address_list;
80 base::TimeDelta ttl;
81 net::DnsResponse::Result result = response.ParseToAddressList(
82 &address_list, &ttl);
83 if (result != net::DnsResponse::DNS_SUCCESS) {
84 printf("ParseToAddressList failed: %d\n", result);
85 return 0;
86 }
87
88 printf("Address List:\n");
89 for (unsigned int i = 0; i < address_list.size(); i++) {
90 std::string address_str = address_list[i].ToString();
91 printf("\t%s\n", address_str.c_str());
92 }
93 printf("TTL: %d seconds\n", static_cast<int>(ttl.InSeconds()));
94
95 return 0;
96 }
97
OLDNEW
« net/net.gyp ('K') | « net/net.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698