 Chromium Code Reviews
 Chromium Code Reviews Issue 10441027:
  Stub binary for fuzzing DNS resolver.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 10441027:
  Stub binary for fuzzing DNS resolver.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| (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> | |
| 
cbentzel
2012/06/01 13:04:38
Do you need stdio.h and stdlib.h anymore?
 | |
| 6 #include <stdlib.h> | |
| 7 #include <string.h> | |
| 
szym
2012/06/01 14:48:08
You don't need <string.h> either, but you do need
 | |
| 8 | |
| 9 #include <algorithm> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/time.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "net/base/address_list.h" | |
| 15 #include "net/base/dns_util.h" | |
| 16 #include "net/base/io_buffer.h" | |
| 17 #include "net/base/ip_endpoint.h" | |
| 18 #include "net/dns/dns_protocol.h" | |
| 19 #include "net/dns/dns_query.h" | |
| 20 #include "net/dns/dns_response.h" | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 // TODO(ttuttle): This should read from the file, probably in JSON. | |
| 25 bool ReadTestCase(const char* filename, | |
| 26 uint16_t* id, std::string* qname, uint16_t* qtype, | |
| 27 std::vector<char>* resp_buf) { | |
| 28 static const unsigned char resp_bytes[] = { | |
| 29 0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, | |
| 30 0x01, 0x61, 0x00, 0x00, 0x01, 0x00, 0x01, | |
| 31 0x01, 0x61, 0x00, 0x00, 0x01, 0x00, 0x01, | |
| 32 0x00, 0x00, 0x00, 0xff, 0x00, 0x04, 0x0a, 0x0a, 0x0a, 0x0a }; | |
| 33 | |
| 34 *id = 0x0000; | |
| 35 *qname = "a"; | |
| 36 *qtype = 0x0001; | |
| 37 resp_buf->assign(resp_bytes, resp_bytes + arraysize(resp_bytes)); | |
| 38 | |
| 39 return true; | |
| 40 } | |
| 41 | |
| 42 } | |
| 43 | |
| 44 int main(int argc, char** argv) { | |
| 45 if (argc != 2) { | |
| 46 LOG(ERROR) << "Usage: " << argv[0] << " test_case_filename"; | |
| 47 return 1; | |
| 48 } | |
| 49 | |
| 50 const char* filename = argv[1]; | |
| 51 | |
| 52 LOG(INFO) << "Test case: " << filename; | |
| 53 | |
| 54 uint16_t id; | |
| 55 std::string qname_dotted; | |
| 56 uint16_t qtype; | |
| 57 std::vector<char> resp_buf; | |
| 58 | |
| 59 if (!ReadTestCase(filename, &id, &qname_dotted, &qtype, &resp_buf)) { | |
| 60 LOG(ERROR) << "Test case format invalid"; | |
| 61 return 2; | |
| 62 } | |
| 63 | |
| 64 LOG(INFO) << "Query: id=" << id | |
| 65 << " qname=" << qname_dotted | |
| 66 << " qtype=" << qtype; | |
| 67 LOG(INFO) << "Response: " << resp_buf.size() << " bytes"; | |
| 68 | |
| 69 std::string qname; | |
| 70 if (!net::DNSDomainFromDot(qname_dotted, &qname)) { | |
| 71 LOG(ERROR) << "DNSDomainFromDot(" << qname_dotted << ") failed."; | |
| 72 return 3; | |
| 73 } | |
| 74 | |
| 75 net::DnsQuery query(id, qname, qtype); | |
| 76 net::DnsResponse response; | |
| 77 std::copy(resp_buf.begin(), resp_buf.end(), response.io_buffer()->data()); | |
| 78 | |
| 79 if (!response.InitParse(resp_buf.size(), query)) { | |
| 80 LOG(INFO) << "InitParse failed."; | |
| 81 return 0; | |
| 82 } | |
| 83 | |
| 84 net::AddressList address_list; | |
| 85 base::TimeDelta ttl; | |
| 86 net::DnsResponse::Result result = response.ParseToAddressList( | |
| 87 &address_list, &ttl); | |
| 88 if (result != net::DnsResponse::DNS_SUCCESS) { | |
| 89 LOG(INFO) << "ParseToAddressList failed: " << result; | |
| 90 return 0; | |
| 91 } | |
| 92 | |
| 93 LOG(INFO) << "Address List:"; | |
| 94 for (unsigned int i = 0; i < address_list.size(); i++) { | |
| 95 LOG(INFO) << "\t" << address_list[i].ToString(); | |
| 96 } | |
| 97 LOG(INFO) << "TTL: " << ttl.InSeconds() << " seconds"; | |
| 98 | |
| 99 return 0; | |
| 100 } | |
| 101 | |
| OLD | NEW |