Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2020 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include "common.h" |
16 | | #include <fuzzer/FuzzedDataProvider.h> |
17 | | |
18 | | #ifndef HASHTYPE |
19 | | #error Macro HASHTYPE must be defined. |
20 | | #endif |
21 | | |
22 | | #ifndef FNAME |
23 | | #error Macro FNAME must be defined. |
24 | | #endif |
25 | | |
26 | 59.3k | #define CONCAT_TYPE(x) _PASTE2(HASHTYPE, x) |
27 | | |
28 | 9.02k | #define init CONCAT_TYPE(_init) |
29 | 35.7k | #define update CONCAT_TYPE(_update) |
30 | 5.57k | #define digest CONCAT_TYPE(_digest) |
31 | 9.02k | #define destroy CONCAT_TYPE(_destroy) |
32 | | |
33 | | #define STR(x) #x |
34 | | #define INCLUDE(x) STR(x) |
35 | | |
36 | | #include INCLUDE(FNAME) |
37 | | |
38 | | #ifndef DIGEST_SIZE |
39 | | #error Macro DIGEST_SIZE must be defined. |
40 | | #endif |
41 | | |
42 | 9.02k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
43 | | |
44 | 9.02k | if (!size) |
45 | 0 | return 0; |
46 | | |
47 | 9.02k | FuzzedDataProvider stream(data, size); |
48 | 9.02k | hash_state *hs; |
49 | 9.02k | if (init(&hs)) |
50 | 0 | return 0; |
51 | | |
52 | 40.1k | while (stream.remaining_bytes()) { |
53 | 35.7k | size_t num_bytes = stream.ConsumeIntegral<size_t>(); |
54 | 35.7k | std::vector<uint8_t> buffer = stream.ConsumeBytes<uint8_t>(num_bytes); |
55 | | |
56 | 35.7k | if (update(hs, buffer.data(), buffer.size())) |
57 | 4.67k | goto error; |
58 | 35.7k | } |
59 | | |
60 | 4.35k | uint8_t result[DIGEST_SIZE]; |
61 | | |
62 | | #ifndef DIGEST_THIRD_PARAM |
63 | 1.08k | digest(hs, result); |
64 | | #else |
65 | 3.26k | digest(hs, result, DIGEST_SIZE); |
66 | | #endif |
67 | | |
68 | 9.02k | error: |
69 | 9.02k | destroy(hs); |
70 | 9.02k | return 0; |
71 | 4.35k | } Line | Count | Source | 42 | 2.25k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | 43 | | | 44 | 2.25k | if (!size) | 45 | 0 | return 0; | 46 | | | 47 | 2.25k | FuzzedDataProvider stream(data, size); | 48 | 2.25k | hash_state *hs; | 49 | 2.25k | if (init(&hs)) | 50 | 0 | return 0; | 51 | | | 52 | 10.0k | while (stream.remaining_bytes()) { | 53 | 8.94k | size_t num_bytes = stream.ConsumeIntegral<size_t>(); | 54 | 8.94k | std::vector<uint8_t> buffer = stream.ConsumeBytes<uint8_t>(num_bytes); | 55 | | | 56 | 8.94k | if (update(hs, buffer.data(), buffer.size())) | 57 | 1.16k | goto error; | 58 | 8.94k | } | 59 | | | 60 | 1.08k | uint8_t result[DIGEST_SIZE]; | 61 | | | 62 | | #ifndef DIGEST_THIRD_PARAM | 63 | | digest(hs, result); | 64 | | #else | 65 | 1.08k | digest(hs, result, DIGEST_SIZE); | 66 | 1.08k | #endif | 67 | | | 68 | 2.25k | error: | 69 | 2.25k | destroy(hs); | 70 | 2.25k | return 0; | 71 | 1.08k | } |
Line | Count | Source | 42 | 2.25k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | 43 | | | 44 | 2.25k | if (!size) | 45 | 0 | return 0; | 46 | | | 47 | 2.25k | FuzzedDataProvider stream(data, size); | 48 | 2.25k | hash_state *hs; | 49 | 2.25k | if (init(&hs)) | 50 | 0 | return 0; | 51 | | | 52 | 10.0k | while (stream.remaining_bytes()) { | 53 | 8.94k | size_t num_bytes = stream.ConsumeIntegral<size_t>(); | 54 | 8.94k | std::vector<uint8_t> buffer = stream.ConsumeBytes<uint8_t>(num_bytes); | 55 | | | 56 | 8.94k | if (update(hs, buffer.data(), buffer.size())) | 57 | 1.16k | goto error; | 58 | 8.94k | } | 59 | | | 60 | 1.08k | uint8_t result[DIGEST_SIZE]; | 61 | | | 62 | 1.08k | #ifndef DIGEST_THIRD_PARAM | 63 | 1.08k | digest(hs, result); | 64 | | #else | 65 | | digest(hs, result, DIGEST_SIZE); | 66 | | #endif | 67 | | | 68 | 2.25k | error: | 69 | 2.25k | destroy(hs); | 70 | 2.25k | return 0; | 71 | 1.08k | } |
Line | Count | Source | 42 | 2.25k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | 43 | | | 44 | 2.25k | if (!size) | 45 | 0 | return 0; | 46 | | | 47 | 2.25k | FuzzedDataProvider stream(data, size); | 48 | 2.25k | hash_state *hs; | 49 | 2.25k | if (init(&hs)) | 50 | 0 | return 0; | 51 | | | 52 | 10.0k | while (stream.remaining_bytes()) { | 53 | 8.94k | size_t num_bytes = stream.ConsumeIntegral<size_t>(); | 54 | 8.94k | std::vector<uint8_t> buffer = stream.ConsumeBytes<uint8_t>(num_bytes); | 55 | | | 56 | 8.94k | if (update(hs, buffer.data(), buffer.size())) | 57 | 1.16k | goto error; | 58 | 8.94k | } | 59 | | | 60 | 1.08k | uint8_t result[DIGEST_SIZE]; | 61 | | | 62 | | #ifndef DIGEST_THIRD_PARAM | 63 | | digest(hs, result); | 64 | | #else | 65 | 1.08k | digest(hs, result, DIGEST_SIZE); | 66 | 1.08k | #endif | 67 | | | 68 | 2.25k | error: | 69 | 2.25k | destroy(hs); | 70 | 2.25k | return 0; | 71 | 1.08k | } |
Line | Count | Source | 42 | 2.25k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | 43 | | | 44 | 2.25k | if (!size) | 45 | 0 | return 0; | 46 | | | 47 | 2.25k | FuzzedDataProvider stream(data, size); | 48 | 2.25k | hash_state *hs; | 49 | 2.25k | if (init(&hs)) | 50 | 0 | return 0; | 51 | | | 52 | 10.0k | while (stream.remaining_bytes()) { | 53 | 8.94k | size_t num_bytes = stream.ConsumeIntegral<size_t>(); | 54 | 8.94k | std::vector<uint8_t> buffer = stream.ConsumeBytes<uint8_t>(num_bytes); | 55 | | | 56 | 8.94k | if (update(hs, buffer.data(), buffer.size())) | 57 | 1.16k | goto error; | 58 | 8.94k | } | 59 | | | 60 | 1.08k | uint8_t result[DIGEST_SIZE]; | 61 | | | 62 | | #ifndef DIGEST_THIRD_PARAM | 63 | | digest(hs, result); | 64 | | #else | 65 | 1.08k | digest(hs, result, DIGEST_SIZE); | 66 | 1.08k | #endif | 67 | | | 68 | 2.25k | error: | 69 | 2.25k | destroy(hs); | 70 | 2.25k | return 0; | 71 | 1.08k | } |
|