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

Side by Side Diff: net/tools/dns_fuzz_stub/dns_fuzz_stub.cc

Issue 82913011: LOG(INFO) tidying in net/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes Created 7 years 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/tools/balsa/balsa_frame.cc ('k') | net/tools/dump_cache/simple_cache_dumper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <sstream> 6 #include <sstream>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "net/base/address_list.h" 17 #include "net/base/address_list.h"
18 #include "net/base/dns_util.h" 18 #include "net/base/dns_util.h"
19 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
20 #include "net/base/ip_endpoint.h" 20 #include "net/base/ip_endpoint.h"
21 #include "net/dns/dns_protocol.h" 21 #include "net/dns/dns_protocol.h"
22 #include "net/dns/dns_query.h" 22 #include "net/dns/dns_query.h"
23 #include "net/dns/dns_response.h" 23 #include "net/dns/dns_response.h"
24 24
25 namespace { 25 namespace {
26 26
27 void CrashDoubleFree(void) { 27 void CrashDoubleFree(void) {
28 // Cause ASAN to detect a double-free 28 // Cause ASAN to detect a double-free
29 void *p = malloc(1); 29 void *p = malloc(1);
30 LOG(INFO) << "Allocated p=" << p << ". Double-freeing..."; 30 VLOG(0) << "Allocated p=" << p << ". Double-freeing...";
31 free(p); 31 free(p);
32 free(p); 32 free(p);
33 } 33 }
34 34
35 void CrashNullPointerDereference(void) { 35 void CrashNullPointerDereference(void) {
36 // Cause the program to segfault with a NULL pointer dereference 36 // Cause the program to segfault with a NULL pointer dereference
37 int *p = NULL; 37 int *p = NULL;
38 *p = 0; 38 *p = 0;
39 } 39 }
40 40
(...skipping 24 matching lines...) Expand all
65 } 65 }
66 66
67 base::DictionaryValue* dict; 67 base::DictionaryValue* dict;
68 if (!value->GetAsDictionary(&dict)) { 68 if (!value->GetAsDictionary(&dict)) {
69 LOG(ERROR) << filename << ": test case is not a dictionary."; 69 LOG(ERROR) << filename << ": test case is not a dictionary.";
70 return false; 70 return false;
71 } 71 }
72 72
73 *crash_test = dict->HasKey("crash_test"); 73 *crash_test = dict->HasKey("crash_test");
74 if (*crash_test) { 74 if (*crash_test) {
75 LOG(INFO) << filename << ": crash_test is set!"; 75 VLOG(0) << filename << ": crash_test is set!";
76 return true; 76 return true;
77 } 77 }
78 78
79 int id_int; 79 int id_int;
80 if (!dict->GetInteger("id", &id_int)) { 80 if (!dict->GetInteger("id", &id_int)) {
81 LOG(ERROR) << filename << ": id is missing or not an integer."; 81 LOG(ERROR) << filename << ": id is missing or not an integer.";
82 return false; 82 return false;
83 } 83 }
84 if (!FitsUint16(id_int)) { 84 if (!FitsUint16(id_int)) {
85 LOG(ERROR) << filename << ": id is out of range."; 85 LOG(ERROR) << filename << ": id is out of range.";
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return false; 119 return false;
120 } 120 }
121 if (!FitsUint8(resp_byte_int)) { 121 if (!FitsUint8(resp_byte_int)) {
122 LOG(ERROR) << filename << ": response[" << i << "] is out of range."; 122 LOG(ERROR) << filename << ": response[" << i << "] is out of range.";
123 return false; 123 return false;
124 } 124 }
125 resp_buf->push_back(static_cast<char>(resp_byte_int)); 125 resp_buf->push_back(static_cast<char>(resp_byte_int));
126 } 126 }
127 DCHECK(resp_buf->size() == resp_size); 127 DCHECK(resp_buf->size() == resp_size);
128 128
129 LOG(INFO) << "Query: id=" << id_int << ", " 129 VLOG(0) << "Query: id=" << id_int << ", "
szym 2013/11/25 17:19:00 Don't know if the fuzzer framework parses the log
scottmg 2013/11/25 17:20:09 I'll revert the changes in this file.
130 << "qname=" << *qname << ", " 130 << "qname=" << *qname << ", "
131 << "qtype=" << qtype_int << ", " 131 << "qtype=" << qtype_int << ", "
132 << "resp_size=" << resp_size; 132 << "resp_size=" << resp_size;
133 133
134 return true; 134 return true;
135 } 135 }
136 136
137 void RunTestCase(uint16 id, std::string& qname, uint16 qtype, 137 void RunTestCase(uint16 id, std::string& qname, uint16 qtype,
138 std::vector<char>& resp_buf) { 138 std::vector<char>& resp_buf) {
139 net::DnsQuery query(id, qname, qtype); 139 net::DnsQuery query(id, qname, qtype);
140 net::DnsResponse response; 140 net::DnsResponse response;
141 std::copy(resp_buf.begin(), resp_buf.end(), response.io_buffer()->data()); 141 std::copy(resp_buf.begin(), resp_buf.end(), response.io_buffer()->data());
142 142
143 if (!response.InitParse(resp_buf.size(), query)) { 143 if (!response.InitParse(resp_buf.size(), query)) {
144 LOG(INFO) << "InitParse failed."; 144 VLOG(0) << "InitParse failed.";
145 return; 145 return;
146 } 146 }
147 147
148 net::AddressList address_list; 148 net::AddressList address_list;
149 base::TimeDelta ttl; 149 base::TimeDelta ttl;
150 net::DnsResponse::Result result = response.ParseToAddressList( 150 net::DnsResponse::Result result = response.ParseToAddressList(
151 &address_list, &ttl); 151 &address_list, &ttl);
152 if (result != net::DnsResponse::DNS_PARSE_OK) { 152 if (result != net::DnsResponse::DNS_PARSE_OK) {
153 LOG(INFO) << "ParseToAddressList failed: " << result; 153 VLOG(0) << "ParseToAddressList failed: " << result;
154 return; 154 return;
155 } 155 }
156 156
157 // Print the response in one compact line. 157 // Print the response in one compact line.
158 std::stringstream result_line; 158 std::stringstream result_line;
159 result_line << "Response: address_list={ "; 159 result_line << "Response: address_list={ ";
160 for (unsigned int i = 0; i < address_list.size(); i++) 160 for (unsigned int i = 0; i < address_list.size(); i++)
161 result_line << address_list[i].ToString() << " "; 161 result_line << address_list[i].ToString() << " ";
162 result_line << "}, ttl=" << ttl.InSeconds() << "s"; 162 result_line << "}, ttl=" << ttl.InSeconds() << "s";
163 163
164 LOG(INFO) << result_line.str(); 164 VLOG(0) << result_line.str();
165 } 165 }
166 166
167 bool ReadAndRunTestCase(const char* filename) { 167 bool ReadAndRunTestCase(const char* filename) {
168 uint16 id = 0; 168 uint16 id = 0;
169 std::string qname; 169 std::string qname;
170 uint16 qtype = 0; 170 uint16 qtype = 0;
171 std::vector<char> resp_buf; 171 std::vector<char> resp_buf;
172 bool crash_test = false; 172 bool crash_test = false;
173 173
174 LOG(INFO) << "Test case: " << filename; 174 VLOG(0) << "Test case: " << filename;
175 175
176 // ReadTestCase will print a useful error message if it fails. 176 // ReadTestCase will print a useful error message if it fails.
177 if (!ReadTestCase(filename, &id, &qname, &qtype, &resp_buf, &crash_test)) 177 if (!ReadTestCase(filename, &id, &qname, &qtype, &resp_buf, &crash_test))
178 return false; 178 return false;
179 179
180 if (crash_test) { 180 if (crash_test) {
181 LOG(INFO) << "Crashing."; 181 VLOG(0) << "Crashing.";
182 CrashDoubleFree(); 182 CrashDoubleFree();
183 // if we're not running under ASAN, that might not have worked 183 // if we're not running under ASAN, that might not have worked
184 CrashNullPointerDereference(); 184 CrashNullPointerDereference();
185 NOTREACHED(); 185 NOTREACHED();
186 return true; 186 return true;
187 } 187 }
188 188
189 std::string qname_dns; 189 std::string qname_dns;
190 if (!net::DNSDomainFromDot(qname, &qname_dns)) { 190 if (!net::DNSDomainFromDot(qname, &qname_dns)) {
191 LOG(ERROR) << filename << ": DNSDomainFromDot(" << qname << ") failed."; 191 LOG(ERROR) << filename << ": DNSDomainFromDot(" << qname << ") failed.";
(...skipping 14 matching lines...) Expand all
206 if (!ReadAndRunTestCase(argv[i])) 206 if (!ReadAndRunTestCase(argv[i]))
207 ret = 2; 207 ret = 2;
208 208
209 // Cluster-Fuzz likes "#EOF" as the last line of output to help distinguish 209 // Cluster-Fuzz likes "#EOF" as the last line of output to help distinguish
210 // successful runs from crashes. 210 // successful runs from crashes.
211 printf("#EOF\n"); 211 printf("#EOF\n");
212 212
213 return ret; 213 return ret;
214 } 214 }
215 215
OLDNEW
« no previous file with comments | « net/tools/balsa/balsa_frame.cc ('k') | net/tools/dump_cache/simple_cache_dumper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698