/src/flac/oss-fuzz/fuzzing/memory.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2019 Guido Vranken |
2 | | * |
3 | | * Permission is hereby granted, free of charge, to any person obtaining |
4 | | * a copy of this software and associated documentation files (the |
5 | | * "Software"), to deal in the Software without restriction, including |
6 | | * without limitation the rights to use, copy, modify, merge, publish, |
7 | | * distribute, sublicense, and/or sell copies of the Software, and to |
8 | | * permit persons to whom the Software is furnished to do so, subject |
9 | | * to the following conditions: |
10 | | * |
11 | | * The above copyright notice and this permission notice shall be |
12 | | * included in all copies or substantial portions of the Software. |
13 | | * |
14 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
15 | | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
16 | | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
17 | | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
18 | | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
19 | | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
20 | | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21 | | * SOFTWARE. |
22 | | */ |
23 | | |
24 | | #pragma once |
25 | | |
26 | | #include <stdio.h> |
27 | | #include <optional> |
28 | | |
29 | | #ifndef ASAN |
30 | | #define ASAN 0 |
31 | | #endif |
32 | | |
33 | | #ifndef MSAN |
34 | | #define MSAN 0 |
35 | | #endif |
36 | | |
37 | | namespace fuzzing { |
38 | | namespace memory { |
39 | | |
40 | | #ifndef FUZZING_HEADERS_NO_IMPL |
41 | | #if ASAN == 1 |
42 | | extern "C" void *__asan_region_is_poisoned(const void *beg, size_t size); |
43 | | #endif |
44 | | |
45 | | #if MSAN == 1 |
46 | | extern "C" void __msan_check_mem_is_initialized(const volatile void *x, size_t size); |
47 | | #endif |
48 | | |
49 | | void memory_test_asan(const void* data, const size_t size) |
50 | 281k | { |
51 | 281k | (void)data; |
52 | 281k | (void)size; |
53 | | |
54 | | #if ASAN == 1 |
55 | | if ( __asan_region_is_poisoned(data, size) != NULL ) { |
56 | | abort(); |
57 | | } |
58 | | #endif |
59 | 281k | } |
60 | | |
61 | | void memory_test_msan(const void* data, const size_t size) |
62 | 281k | { |
63 | 281k | (void)data; |
64 | 281k | (void)size; |
65 | | |
66 | | #if MSAN == 1 |
67 | | __msan_check_mem_is_initialized(data, size); |
68 | | #endif |
69 | 281k | } |
70 | | |
71 | | void memory_test(const void* data, const size_t size) |
72 | 281k | { |
73 | 281k | memory_test_asan(data, size); |
74 | 281k | memory_test_msan(data, size); |
75 | 281k | } |
76 | | |
77 | | template <class T> |
78 | | void memory_test(const T& t) |
79 | 771k | { |
80 | 771k | (void)t; |
81 | 771k | } void fuzzing::memory::memory_test<unsigned long>(unsigned long const&) Line | Count | Source | 79 | 126k | { | 80 | 126k | (void)t; | 81 | 126k | } |
void fuzzing::memory::memory_test<FLAC__MetadataType>(FLAC__MetadataType const&) Line | Count | Source | 79 | 23.8k | { | 80 | 23.8k | (void)t; | 81 | 23.8k | } |
void fuzzing::memory::memory_test<int>(int const&) Line | Count | Source | 79 | 23.8k | { | 80 | 23.8k | (void)t; | 81 | 23.8k | } |
void fuzzing::memory::memory_test<unsigned int>(unsigned int const&) Line | Count | Source | 79 | 23.8k | { | 80 | 23.8k | (void)t; | 81 | 23.8k | } |
void fuzzing::memory::memory_test<FLAC__StreamMetadata::{unnamed type#1}>(FLAC__StreamMetadata::{unnamed type#1} const&) Line | Count | Source | 79 | 23.8k | { | 80 | 23.8k | (void)t; | 81 | 23.8k | } |
void fuzzing::memory::memory_test<FLAC__StreamDecoderErrorStatus>(FLAC__StreamDecoderErrorStatus const&) Line | Count | Source | 79 | 252k | { | 80 | 252k | (void)t; | 81 | 252k | } |
void fuzzing::memory::memory_test<bool>(bool const&) Line | Count | Source | 79 | 297k | { | 80 | 297k | (void)t; | 81 | 297k | } |
|
82 | | |
83 | | template <> |
84 | | void memory_test(const std::string& s) |
85 | 0 | { |
86 | 0 | (void)s; |
87 | |
|
88 | | #if MSAN == 1 |
89 | | memory_test(s.data(), s.size()); |
90 | | #endif |
91 | 0 | } |
92 | | |
93 | | #endif |
94 | | |
95 | | } /* namespace memory */ |
96 | | } /* namespace fuzzing */ |