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

Side by Side Diff: net/spdy/fuzzing/hpack_fuzz_util.cc

Issue 1471073010: Removed unused include of winsock.h/inet.h from sys_byteorder.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include inet.h for things other than byte-swap 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/dns/dns_config_service_posix_unittest.cc ('k') | net/spdy/spdy_frame_builder.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "net/spdy/fuzzing/hpack_fuzz_util.h" 5 #include "net/spdy/fuzzing/hpack_fuzz_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // static 114 // static
115 bool HpackFuzzUtil::NextHeaderBlock(Input* input, 115 bool HpackFuzzUtil::NextHeaderBlock(Input* input,
116 StringPiece* out) { 116 StringPiece* out) {
117 // ClusterFuzz may truncate input files if the fuzzer ran out of allocated 117 // ClusterFuzz may truncate input files if the fuzzer ran out of allocated
118 // disk space. Be tolerant of these. 118 // disk space. Be tolerant of these.
119 CHECK_LE(input->offset, input->input.size()); 119 CHECK_LE(input->offset, input->input.size());
120 if (input->remaining() < sizeof(uint32)) { 120 if (input->remaining() < sizeof(uint32)) {
121 return false; 121 return false;
122 } 122 }
123 123
124 size_t length = ntohl(*reinterpret_cast<const uint32*>(input->ptr())); 124 size_t length =
125 base::NetToHost32(*reinterpret_cast<const uint32*>(input->ptr()));
125 input->offset += sizeof(uint32); 126 input->offset += sizeof(uint32);
126 127
127 if (input->remaining() < length) { 128 if (input->remaining() < length) {
128 return false; 129 return false;
129 } 130 }
130 *out = StringPiece(input->ptr(), length); 131 *out = StringPiece(input->ptr(), length);
131 input->offset += length; 132 input->offset += length;
132 return true; 133 return true;
133 } 134 }
134 135
135 // static 136 // static
136 string HpackFuzzUtil::HeaderBlockPrefix(size_t block_size) { 137 string HpackFuzzUtil::HeaderBlockPrefix(size_t block_size) {
137 uint32 length = htonl(block_size); 138 uint32 length = base::HostToNet32(static_cast<uint32>(block_size));
138 return string(reinterpret_cast<char*>(&length), sizeof(uint32)); 139 return string(reinterpret_cast<char*>(&length), sizeof(uint32));
139 } 140 }
140 141
141 // static 142 // static
142 void HpackFuzzUtil::InitializeFuzzerContext(FuzzerContext* context) { 143 void HpackFuzzUtil::InitializeFuzzerContext(FuzzerContext* context) {
143 context->first_stage.reset(new HpackDecoder(ObtainHpackHuffmanTable())); 144 context->first_stage.reset(new HpackDecoder(ObtainHpackHuffmanTable()));
144 context->second_stage.reset(new HpackEncoder(ObtainHpackHuffmanTable())); 145 context->second_stage.reset(new HpackEncoder(ObtainHpackHuffmanTable()));
145 context->third_stage.reset(new HpackDecoder(ObtainHpackHuffmanTable())); 146 context->third_stage.reset(new HpackDecoder(ObtainHpackHuffmanTable()));
146 } 147 }
147 148
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 uint64 bits_to_flip = flip_per_thousand * (1 + buffer_bit_length / 1024); 182 uint64 bits_to_flip = flip_per_thousand * (1 + buffer_bit_length / 1024);
182 183
183 // Iteratively identify & flip offsets in the buffer bit-sequence. 184 // Iteratively identify & flip offsets in the buffer bit-sequence.
184 for (uint64 i = 0; i != bits_to_flip; ++i) { 185 for (uint64 i = 0; i != bits_to_flip; ++i) {
185 uint64 bit_offset = base::RandUint64() % buffer_bit_length; 186 uint64 bit_offset = base::RandUint64() % buffer_bit_length;
186 buffer[bit_offset / 8u] ^= (1 << (bit_offset % 8u)); 187 buffer[bit_offset / 8u] ^= (1 << (bit_offset % 8u));
187 } 188 }
188 } 189 }
189 190
190 } // namespace net 191 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_config_service_posix_unittest.cc ('k') | net/spdy/spdy_frame_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698