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

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

Issue 1475803002: Remove kuint16max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint2
Patch Set: cloud print Created 5 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
« no previous file with comments | « net/test/spawned_test_server/spawner_communicator.cc ('k') | sandbox/win/src/sandbox_nt_util.h » ('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 <stdint.h>
6
5 #include <algorithm> 7 #include <algorithm>
8 #include <limits>
6 #include <sstream> 9 #include <sstream>
7 #include <string> 10 #include <string>
8 #include <vector> 11 #include <vector>
9 12
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
13 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
14 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
15 #include "base/time/time.h" 17 #include "base/time/time.h"
16 #include "base/values.h" 18 #include "base/values.h"
17 #include "net/base/address_list.h" 19 #include "net/base/address_list.h"
18 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
19 #include "net/base/ip_endpoint.h" 21 #include "net/base/ip_endpoint.h"
20 #include "net/dns/dns_protocol.h" 22 #include "net/dns/dns_protocol.h"
(...skipping 11 matching lines...) Expand all
32 free(p); 34 free(p);
33 } 35 }
34 36
35 void CrashNullPointerDereference(void) { 37 void CrashNullPointerDereference(void) {
36 // Cause the program to segfault with a NULL pointer dereference 38 // Cause the program to segfault with a NULL pointer dereference
37 int *p = NULL; 39 int *p = NULL;
38 *p = 0; 40 *p = 0;
39 } 41 }
40 42
41 bool FitsUint8(int num) { 43 bool FitsUint8(int num) {
42 return (num >= 0) && (num <= kuint8max); 44 return (num >= 0) && (num <= std::numeric_limits<uint8_t>::max());
43 } 45 }
44 46
45 bool FitsUint16(int num) { 47 bool FitsUint16(int num) {
46 return (num >= 0) && (num <= kuint16max); 48 return (num >= 0) && (num <= std::numeric_limits<uint16_t>::max());
47 } 49 }
48 50
49 bool ReadTestCase(const char* filename, 51 bool ReadTestCase(const char* filename,
50 uint16* id, std::string* qname, uint16* qtype, 52 uint16_t* id,
53 std::string* qname,
54 uint16_t* qtype,
51 std::vector<char>* resp_buf, 55 std::vector<char>* resp_buf,
52 bool* crash_test) { 56 bool* crash_test) {
53 base::FilePath filepath = base::FilePath::FromUTF8Unsafe(filename); 57 base::FilePath filepath = base::FilePath::FromUTF8Unsafe(filename);
54 58
55 std::string json; 59 std::string json;
56 if (!base::ReadFileToString(filepath, &json)) { 60 if (!base::ReadFileToString(filepath, &json)) {
57 LOG(ERROR) << filename << ": couldn't read file."; 61 LOG(ERROR) << filename << ": couldn't read file.";
58 return false; 62 return false;
59 } 63 }
60 64
(...skipping 17 matching lines...) Expand all
78 82
79 int id_int; 83 int id_int;
80 if (!dict->GetInteger("id", &id_int)) { 84 if (!dict->GetInteger("id", &id_int)) {
81 LOG(ERROR) << filename << ": id is missing or not an integer."; 85 LOG(ERROR) << filename << ": id is missing or not an integer.";
82 return false; 86 return false;
83 } 87 }
84 if (!FitsUint16(id_int)) { 88 if (!FitsUint16(id_int)) {
85 LOG(ERROR) << filename << ": id is out of range."; 89 LOG(ERROR) << filename << ": id is out of range.";
86 return false; 90 return false;
87 } 91 }
88 *id = static_cast<uint16>(id_int); 92 *id = static_cast<uint16_t>(id_int);
89 93
90 if (!dict->GetStringASCII("qname", qname)) { 94 if (!dict->GetStringASCII("qname", qname)) {
91 LOG(ERROR) << filename << ": qname is missing or not a string."; 95 LOG(ERROR) << filename << ": qname is missing or not a string.";
92 return false; 96 return false;
93 } 97 }
94 98
95 int qtype_int; 99 int qtype_int;
96 if (!dict->GetInteger("qtype", &qtype_int)) { 100 if (!dict->GetInteger("qtype", &qtype_int)) {
97 LOG(ERROR) << filename << ": qtype is missing or not an integer."; 101 LOG(ERROR) << filename << ": qtype is missing or not an integer.";
98 return false; 102 return false;
99 } 103 }
100 if (!FitsUint16(qtype_int)) { 104 if (!FitsUint16(qtype_int)) {
101 LOG(ERROR) << filename << ": qtype is out of range."; 105 LOG(ERROR) << filename << ": qtype is out of range.";
102 return false; 106 return false;
103 } 107 }
104 *qtype = static_cast<uint16>(qtype_int); 108 *qtype = static_cast<uint16_t>(qtype_int);
105 109
106 base::ListValue* resp_list; 110 base::ListValue* resp_list;
107 if (!dict->GetList("response", &resp_list)) { 111 if (!dict->GetList("response", &resp_list)) {
108 LOG(ERROR) << filename << ": response is missing or not a list."; 112 LOG(ERROR) << filename << ": response is missing or not a list.";
109 return false; 113 return false;
110 } 114 }
111 115
112 size_t resp_size = resp_list->GetSize(); 116 size_t resp_size = resp_list->GetSize();
113 resp_buf->clear(); 117 resp_buf->clear();
114 resp_buf->reserve(resp_size); 118 resp_buf->reserve(resp_size);
(...skipping 12 matching lines...) Expand all
127 DCHECK(resp_buf->size() == resp_size); 131 DCHECK(resp_buf->size() == resp_size);
128 132
129 LOG(INFO) << "Query: id=" << id_int << ", " 133 LOG(INFO) << "Query: id=" << id_int << ", "
130 << "qname=" << *qname << ", " 134 << "qname=" << *qname << ", "
131 << "qtype=" << qtype_int << ", " 135 << "qtype=" << qtype_int << ", "
132 << "resp_size=" << resp_size; 136 << "resp_size=" << resp_size;
133 137
134 return true; 138 return true;
135 } 139 }
136 140
137 void RunTestCase(uint16 id, std::string& qname, uint16 qtype, 141 void RunTestCase(uint16_t id,
142 std::string& qname,
143 uint16_t qtype,
138 std::vector<char>& resp_buf) { 144 std::vector<char>& resp_buf) {
139 net::DnsQuery query(id, qname, qtype); 145 net::DnsQuery query(id, qname, qtype);
140 net::DnsResponse response; 146 net::DnsResponse response;
141 std::copy(resp_buf.begin(), resp_buf.end(), response.io_buffer()->data()); 147 std::copy(resp_buf.begin(), resp_buf.end(), response.io_buffer()->data());
142 148
143 if (!response.InitParse(resp_buf.size(), query)) { 149 if (!response.InitParse(resp_buf.size(), query)) {
144 LOG(INFO) << "InitParse failed."; 150 LOG(INFO) << "InitParse failed.";
145 return; 151 return;
146 } 152 }
147 153
(...skipping 10 matching lines...) Expand all
158 std::stringstream result_line; 164 std::stringstream result_line;
159 result_line << "Response: address_list={ "; 165 result_line << "Response: address_list={ ";
160 for (unsigned int i = 0; i < address_list.size(); i++) 166 for (unsigned int i = 0; i < address_list.size(); i++)
161 result_line << address_list[i].ToString() << " "; 167 result_line << address_list[i].ToString() << " ";
162 result_line << "}, ttl=" << ttl.InSeconds() << "s"; 168 result_line << "}, ttl=" << ttl.InSeconds() << "s";
163 169
164 LOG(INFO) << result_line.str(); 170 LOG(INFO) << result_line.str();
165 } 171 }
166 172
167 bool ReadAndRunTestCase(const char* filename) { 173 bool ReadAndRunTestCase(const char* filename) {
168 uint16 id = 0; 174 uint16_t id = 0;
169 std::string qname; 175 std::string qname;
170 uint16 qtype = 0; 176 uint16_t qtype = 0;
171 std::vector<char> resp_buf; 177 std::vector<char> resp_buf;
172 bool crash_test = false; 178 bool crash_test = false;
173 179
174 LOG(INFO) << "Test case: " << filename; 180 LOG(INFO) << "Test case: " << filename;
175 181
176 // ReadTestCase will print a useful error message if it fails. 182 // ReadTestCase will print a useful error message if it fails.
177 if (!ReadTestCase(filename, &id, &qname, &qtype, &resp_buf, &crash_test)) 183 if (!ReadTestCase(filename, &id, &qname, &qtype, &resp_buf, &crash_test))
178 return false; 184 return false;
179 185
180 if (crash_test) { 186 if (crash_test) {
(...skipping 25 matching lines...) Expand all
206 if (!ReadAndRunTestCase(argv[i])) 212 if (!ReadAndRunTestCase(argv[i]))
207 ret = 2; 213 ret = 2;
208 214
209 // Cluster-Fuzz likes "#EOF" as the last line of output to help distinguish 215 // Cluster-Fuzz likes "#EOF" as the last line of output to help distinguish
210 // successful runs from crashes. 216 // successful runs from crashes.
211 printf("#EOF\n"); 217 printf("#EOF\n");
212 218
213 return ret; 219 return ret;
214 } 220 }
215 221
OLDNEW
« no previous file with comments | « net/test/spawned_test_server/spawner_communicator.cc ('k') | sandbox/win/src/sandbox_nt_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698