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

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, 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
« 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 #include <stdio.h>
szym 2012/05/24 19:41:02 Add licence.
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Done.
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "base/time.h"
6 #include "net/base/address_list.h"
7 #include "net/base/dns_util.h"
8 #include "net/base/io_buffer.h"
9 #include "net/base/ip_endpoint.h"
10 #include "net/dns/dns_protocol.h"
11 #include "net/dns/dns_query.h"
12 #include "net/dns/dns_response.h"
13
14 using namespace net;
szym 2012/05/24 19:41:02 Don't go using whole namespaces. Probably just put
szym 2012/05/24 19:42:30 Another option is to just go using net::DnsQuery;
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Will that work if the compiler is expecting to cal
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Done.
15
16 static int usage(const char* progn) {
szym 2012/05/24 19:41:02 Preferred: "Usage". Expand |program_name|.
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Done.
17 fprintf(stderr, "Usage: %s test_case_filename\n", progn);
18 return 1;
19 }
20
21 #define MAX_DOMAIN 256
szym 2012/05/24 19:41:02 const unsigned kMaxDomain. If this is meant to be
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Done.
22
23 int main(int argc, char** argv) {
24 // base::AtExitManager at_exit_manager;
szym 2012/05/24 19:42:30 You probably don't need it.
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Done.
25
26 if (argc < 1)
Deprecated (see juliatuttle) 2012/05/24 21:53:35 This should've been argc < 2 ;)
27 return usage(argv[0]);
28
29 const char* filename = argv[1];
30 FILE* file = fopen(filename, "r");
szym 2012/05/24 19:41:02 Consider using file_util. Up to you.
31 if (!file) {
32 perror("open");
33 return usage(argv[0]);
34 }
35
36 uint16_t id;
37 char qname_dotted[MAX_DOMAIN];
38 uint16_t qtype;
39
40 /* XXX: You can overflow domain. */
szym 2012/05/24 19:41:02 All comments are //.
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Done.
41 fscanf(file, "%hu %s %hu\n", &id, qname_dotted, &qtype);
szym 2012/05/24 19:41:02 Check that it worked.
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Done.
42
43 printf("Query: id=%hu name=%s type=%hu\n", id, qname_dotted, qtype);
szym 2012/05/24 19:41:02 What happens to the output? Is it automatically pa
Deprecated (see juliatuttle) 2012/05/24 21:53:35 The harness only catches crashes. This is just fo
44
45 unsigned int response_len;
46 fscanf(file, "%d ", &response_len);
47 char* response_buf = reinterpret_cast<char*>(malloc(response_len));
szym 2012/05/24 19:41:02 No malloc. Use new.
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Done.
48 for (unsigned int i = 0; i < response_len; i++) {
49 fscanf(file, "%02hhx ", &response_buf[i]);
50 }
51
52 printf("Response: %u bytes\n", response_len);
53
54 std::string qname;
55 if (!DNSDomainFromDot(qname_dotted, &qname)) {
56 fprintf(stderr, "DNSDomainFromDot failed.\n");
57 return 1;
58 }
59
60 DnsQuery query(id, qname, qtype);
61 DnsResponse response;
62 memcpy(response.io_buffer()->data(), response_buf, response_len);
63
64 if (!response.InitParse(response_len, query)) {
65 fprintf(stderr, "InitParse failed.\n");
66 return 1;
67 }
68
69 AddressList address_list;
70 base::TimeDelta ttl;
71 DnsResponse::Result result = response.ParseToAddressList(
72 &address_list, &ttl);
73 if (result != DnsResponse::DNS_SUCCESS) {
74 fprintf(stderr, "ParseToAddressList failed: %d\n", result);
szym 2012/05/24 19:41:02 Should you return an error code here for the harne
Deprecated (see juliatuttle) 2012/05/24 21:53:35 No. This is not an error. We're happy if it retu
75 }
76
77 printf("Address List: %d addresses\n", (int)address_list.size());
78 for (unsigned int i = 0; i < address_list.size(); i++) {
79 std::string address_str = address_list[i].ToString();
80 printf("\t%s\n", address_str.c_str());
81 }
82 printf("TTL: %d seconds\n", (int)ttl.InSeconds());
83
84 return 0;
85 }
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