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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/net.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/dns_fuzz_stub/dns_fuzz_stub.cc
diff --git a/net/tools/dns_fuzz_stub/dns_fuzz_stub.cc b/net/tools/dns_fuzz_stub/dns_fuzz_stub.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aeb7589341ce1f6250072a19ad9383244ae946ff
--- /dev/null
+++ b/net/tools/dns_fuzz_stub/dns_fuzz_stub.cc
@@ -0,0 +1,85 @@
+#include <stdio.h>
szym 2012/05/24 19:41:02 Add licence.
Deprecated (see juliatuttle) 2012/05/24 21:53:35 Done.
+#include <stdlib.h>
+#include <string.h>
+
+#include "base/time.h"
+#include "net/base/address_list.h"
+#include "net/base/dns_util.h"
+#include "net/base/io_buffer.h"
+#include "net/base/ip_endpoint.h"
+#include "net/dns/dns_protocol.h"
+#include "net/dns/dns_query.h"
+#include "net/dns/dns_response.h"
+
+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.
+
+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.
+ fprintf(stderr, "Usage: %s test_case_filename\n", progn);
+ return 1;
+}
+
+#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.
+
+int main(int argc, char** argv) {
+ // 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.
+
+ if (argc < 1)
Deprecated (see juliatuttle) 2012/05/24 21:53:35 This should've been argc < 2 ;)
+ return usage(argv[0]);
+
+ const char* filename = argv[1];
+ FILE* file = fopen(filename, "r");
szym 2012/05/24 19:41:02 Consider using file_util. Up to you.
+ if (!file) {
+ perror("open");
+ return usage(argv[0]);
+ }
+
+ uint16_t id;
+ char qname_dotted[MAX_DOMAIN];
+ uint16_t qtype;
+
+ /* 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.
+ 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.
+
+ 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
+
+ unsigned int response_len;
+ fscanf(file, "%d ", &response_len);
+ 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.
+ for (unsigned int i = 0; i < response_len; i++) {
+ fscanf(file, "%02hhx ", &response_buf[i]);
+ }
+
+ printf("Response: %u bytes\n", response_len);
+
+ std::string qname;
+ if (!DNSDomainFromDot(qname_dotted, &qname)) {
+ fprintf(stderr, "DNSDomainFromDot failed.\n");
+ return 1;
+ }
+
+ DnsQuery query(id, qname, qtype);
+ DnsResponse response;
+ memcpy(response.io_buffer()->data(), response_buf, response_len);
+
+ if (!response.InitParse(response_len, query)) {
+ fprintf(stderr, "InitParse failed.\n");
+ return 1;
+ }
+
+ AddressList address_list;
+ base::TimeDelta ttl;
+ DnsResponse::Result result = response.ParseToAddressList(
+ &address_list, &ttl);
+ if (result != DnsResponse::DNS_SUCCESS) {
+ 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
+ }
+
+ printf("Address List: %d addresses\n", (int)address_list.size());
+ for (unsigned int i = 0; i < address_list.size(); i++) {
+ std::string address_str = address_list[i].ToString();
+ printf("\t%s\n", address_str.c_str());
+ }
+ printf("TTL: %d seconds\n", (int)ttl.InSeconds());
+
+ return 0;
+}
« 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