| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 constexpr size_t BYTES_CONSUMED_BY_PARAMS = 2; | 38 constexpr size_t BYTES_CONSUMED_BY_PARAMS = 2; |
| 39 | 39 |
| 40 // If there are exactly BYTES_CONSUMED_BY_PARAMS + MIN_BYTES_TO_CREATE_A_FRAME | 40 // If there are exactly BYTES_CONSUMED_BY_PARAMS + MIN_BYTES_TO_CREATE_A_FRAME |
| 41 // bytes of input, then the fuzzer will test a single frame. In order to also | 41 // bytes of input, then the fuzzer will test a single frame. In order to also |
| 42 // test the case with zero frames, allow one less byte than this. | 42 // test the case with zero frames, allow one less byte than this. |
| 43 constexpr size_t MIN_USEFUL_SIZE = | 43 constexpr size_t MIN_USEFUL_SIZE = |
| 44 BYTES_CONSUMED_BY_PARAMS + MIN_BYTES_TO_CREATE_A_FRAME - 1; | 44 BYTES_CONSUMED_BY_PARAMS + MIN_BYTES_TO_CREATE_A_FRAME - 1; |
| 45 | 45 |
| 46 class WebSocketFuzzedStream final : public WebSocketStream { | 46 class WebSocketFuzzedStream final : public WebSocketStream { |
| 47 public: | 47 public: |
| 48 WebSocketFuzzedStream(base::FuzzedDataProvider* fuzzed_data_provider) | 48 explicit WebSocketFuzzedStream(base::FuzzedDataProvider* fuzzed_data_provider) |
| 49 : fuzzed_data_provider_(fuzzed_data_provider) {} | 49 : fuzzed_data_provider_(fuzzed_data_provider) {} |
| 50 | 50 |
| 51 int ReadFrames(std::vector<std::unique_ptr<WebSocketFrame>>* frames, | 51 int ReadFrames(std::vector<std::unique_ptr<WebSocketFrame>>* frames, |
| 52 const CompletionCallback& callback) override { | 52 const CompletionCallback& callback) override { |
| 53 if (fuzzed_data_provider_->remaining_bytes() < MIN_BYTES_TO_CREATE_A_FRAME) | 53 if (fuzzed_data_provider_->remaining_bytes() < MIN_BYTES_TO_CREATE_A_FRAME) |
| 54 return ERR_CONNECTION_CLOSED; | 54 return ERR_CONNECTION_CLOSED; |
| 55 while (fuzzed_data_provider_->remaining_bytes() > 0) | 55 while (fuzzed_data_provider_->remaining_bytes() > 0) |
| 56 frames->push_back(CreateFrame()); | 56 frames->push_back(CreateFrame()); |
| 57 return OK; | 57 return OK; |
| 58 } | 58 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } // namespace net | 126 } // namespace net |
| 127 | 127 |
| 128 // Entry point for LibFuzzer. | 128 // Entry point for LibFuzzer. |
| 129 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 129 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 130 if (size < net::MIN_USEFUL_SIZE) | 130 if (size < net::MIN_USEFUL_SIZE) |
| 131 return 0; | 131 return 0; |
| 132 net::WebSocketDeflateStreamFuzz(data, size); | 132 net::WebSocketDeflateStreamFuzz(data, size); |
| 133 | 133 |
| 134 return 0; | 134 return 0; |
| 135 } | 135 } |
| OLD | NEW |