/src/libfsapfs/ossfuzz/volume_fuzzer.cc
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * OSS-Fuzz target for libfsapfs volume type | 
| 3 |  |  * | 
| 4 |  |  * Copyright (C) 2018-2024, Joachim Metz <joachim.metz@gmail.com> | 
| 5 |  |  * | 
| 6 |  |  * Refer to AUTHORS for acknowledgements. | 
| 7 |  |  * | 
| 8 |  |  * This program is free software: you can redistribute it and/or modify | 
| 9 |  |  * it under the terms of the GNU Lesser General Public License as published by | 
| 10 |  |  * the Free Software Foundation, either version 3 of the License, or | 
| 11 |  |  * (at your option) any later version. | 
| 12 |  |  * | 
| 13 |  |  * This program is distributed in the hope that it will be useful, | 
| 14 |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 15 |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 16 |  |  * GNU General Public License for more details. | 
| 17 |  |  * | 
| 18 |  |  * You should have received a copy of the GNU Lesser General Public License | 
| 19 |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
| 20 |  |  */ | 
| 21 |  |  | 
| 22 |  | #include <stddef.h> | 
| 23 |  | #include <stdint.h> | 
| 24 |  |  | 
| 25 |  | /* Note that some of the OSS-Fuzz engines use C++ | 
| 26 |  |  */ | 
| 27 |  | extern "C" { | 
| 28 |  |  | 
| 29 |  | #include "ossfuzz_libbfio.h" | 
| 30 |  | #include "ossfuzz_libfsapfs.h" | 
| 31 |  |  | 
| 32 |  | #if !defined( LIBFSAPFS_HAVE_BFIO ) | 
| 33 |  |  | 
| 34 |  | /* Opens a container using a Basic File IO (bfio) handle | 
| 35 |  |  * Returns 1 if successful or -1 on error | 
| 36 |  |  */ | 
| 37 |  | LIBFSAPFS_EXTERN \ | 
| 38 |  | int libfsapfs_container_open_file_io_handle( | 
| 39 |  |      libfsapfs_container_t *container, | 
| 40 |  |      libbfio_handle_t *file_io_handle, | 
| 41 |  |      int access_flags, | 
| 42 |  |      libfsapfs_error_t **error ); | 
| 43 |  |  | 
| 44 |  | #endif /* !defined( LIBFSAPFS_HAVE_BFIO ) */ | 
| 45 |  |  | 
| 46 |  | int LLVMFuzzerTestOneInput( | 
| 47 |  |      const uint8_t *data, | 
| 48 |  |      size_t size ) | 
| 49 | 3.26k | { | 
| 50 | 3.26k |   uint8_t volume_identifier[ 16 ]; | 
| 51 | 3.26k |   uint8_t string_value[ 64 ]; | 
| 52 |  |  | 
| 53 | 3.26k |   libbfio_handle_t *file_io_handle             = NULL; | 
| 54 | 3.26k |   libfsapfs_container_t *container             = NULL; | 
| 55 | 3.26k |   libfsapfs_volume_t *volume                   = NULL; | 
| 56 | 3.26k |   size64_t volume_size                         = 0; | 
| 57 | 3.26k |   size_t string_size                           = 0; | 
| 58 | 3.26k |   uint64_t compatible_features_flags           = 0; | 
| 59 | 3.26k |   uint64_t incompatible_features_flags         = 0; | 
| 60 | 3.26k |   uint64_t read_only_compatible_features_flags = 0; | 
| 61 | 3.26k |   int number_of_volumes                        = 0; | 
| 62 | 3.26k |   int result                                   = 0; | 
| 63 |  |  | 
| 64 | 3.26k |   if( libbfio_memory_range_initialize( | 
| 65 | 3.26k |        &file_io_handle, | 
| 66 | 3.26k |        NULL ) != 1 ) | 
| 67 | 0 |   { | 
| 68 | 0 |     return( 0 ); | 
| 69 | 0 |   } | 
| 70 | 3.26k |   if( libbfio_memory_range_set( | 
| 71 | 3.26k |        file_io_handle, | 
| 72 | 3.26k |        (uint8_t *) data, | 
| 73 | 3.26k |        size, | 
| 74 | 3.26k |        NULL ) != 1 ) | 
| 75 | 0 |   { | 
| 76 | 0 |     goto on_error_libbfio; | 
| 77 | 0 |   } | 
| 78 | 3.26k |   if( libfsapfs_container_initialize( | 
| 79 | 3.26k |        &container, | 
| 80 | 3.26k |        NULL ) != 1 ) | 
| 81 | 0 |   { | 
| 82 | 0 |     goto on_error_libbfio; | 
| 83 | 0 |   } | 
| 84 | 3.26k |   if( libfsapfs_container_open_file_io_handle( | 
| 85 | 3.26k |        container, | 
| 86 | 3.26k |        file_io_handle, | 
| 87 | 3.26k |        LIBFSAPFS_OPEN_READ, | 
| 88 | 3.26k |        NULL ) != 1 ) | 
| 89 | 1.36k |   { | 
| 90 | 1.36k |     goto on_error_libfsapfs_container; | 
| 91 | 1.36k |   } | 
| 92 | 1.90k |   if( libfsapfs_container_get_number_of_volumes( | 
| 93 | 1.90k |        container, | 
| 94 | 1.90k |        &number_of_volumes, | 
| 95 | 1.90k |        NULL ) != 1 ) | 
| 96 | 0 |   { | 
| 97 | 0 |     goto on_error_libfsapfs_container; | 
| 98 | 0 |   } | 
| 99 | 1.90k |   if( number_of_volumes > 0 ) | 
| 100 | 1.90k |   { | 
| 101 | 1.90k |     result = libfsapfs_container_get_volume_by_index( | 
| 102 | 1.90k |               container, | 
| 103 | 1.90k |               0, | 
| 104 | 1.90k |               &volume, | 
| 105 | 1.90k |               NULL ); | 
| 106 |  |  | 
| 107 | 1.90k |     if( result != -1 ) | 
| 108 | 27 |     { | 
| 109 | 27 |       libfsapfs_volume_get_features_flags( | 
| 110 | 27 |        volume, | 
| 111 | 27 |        &compatible_features_flags, | 
| 112 | 27 |        &incompatible_features_flags, | 
| 113 | 27 |        &read_only_compatible_features_flags, | 
| 114 | 27 |        NULL ); | 
| 115 |  |  | 
| 116 | 27 |       libfsapfs_volume_get_size( | 
| 117 | 27 |        volume, | 
| 118 | 27 |        &volume_size, | 
| 119 | 27 |        NULL ); | 
| 120 |  |  | 
| 121 | 27 |       libfsapfs_volume_get_identifier( | 
| 122 | 27 |        volume, | 
| 123 | 27 |        volume_identifier, | 
| 124 | 27 |        16, | 
| 125 | 27 |        NULL ); | 
| 126 |  |  | 
| 127 | 27 |       libfsapfs_volume_get_utf8_name_size( | 
| 128 | 27 |        volume, | 
| 129 | 27 |        &string_size, | 
| 130 | 27 |        NULL ); | 
| 131 |  |  | 
| 132 | 27 |       libfsapfs_volume_get_utf8_name( | 
| 133 | 27 |        volume, | 
| 134 | 27 |        string_value, | 
| 135 | 27 |        64, | 
| 136 | 27 |        NULL ); | 
| 137 |  |  | 
| 138 | 27 |       libfsapfs_volume_is_locked( | 
| 139 | 27 |        volume, | 
| 140 | 27 |        NULL ); | 
| 141 |  |  | 
| 142 | 27 |       libfsapfs_volume_free( | 
| 143 | 27 |        &volume, | 
| 144 | 27 |        NULL ); | 
| 145 | 27 |     } | 
| 146 | 1.90k |   } | 
| 147 | 3.26k | on_error_libfsapfs_container: | 
| 148 | 3.26k |   libfsapfs_container_free( | 
| 149 | 3.26k |    &container, | 
| 150 | 3.26k |    NULL ); | 
| 151 |  |  | 
| 152 | 3.26k | on_error_libbfio: | 
| 153 | 3.26k |   libbfio_handle_free( | 
| 154 | 3.26k |    &file_io_handle, | 
| 155 | 3.26k |    NULL ); | 
| 156 |  |  | 
| 157 | 3.26k |   return( 0 ); | 
| 158 | 3.26k | } | 
| 159 |  |  | 
| 160 |  | } /* extern "C" */ | 
| 161 |  |  |