/src/libfsext/ossfuzz/extended_attribute_fuzzer.cc
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * OSS-Fuzz target for libfsext extended_attribute type | 
| 3 |  |  * | 
| 4 |  |  * Copyright (C) 2010-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_libfsext.h" | 
| 31 |  |  | 
| 32 |  | #if !defined( LIBFSEXT_HAVE_BFIO ) | 
| 33 |  |  | 
| 34 |  | /* Opens a volume using a Basic File IO (bfio) handle | 
| 35 |  |  * Returns 1 if successful or -1 on error | 
| 36 |  |  */ | 
| 37 |  | LIBFSEXT_EXTERN \ | 
| 38 |  | int libfsext_volume_open_file_io_handle( | 
| 39 |  |      libfsext_volume_t *volume, | 
| 40 |  |      libbfio_handle_t *file_io_handle, | 
| 41 |  |      int access_flags, | 
| 42 |  |      libfsext_error_t **error ); | 
| 43 |  |  | 
| 44 |  | #endif /* !defined( LIBFSEXT_HAVE_BFIO ) */ | 
| 45 |  |  | 
| 46 |  | int LLVMFuzzerTestOneInput( | 
| 47 |  |      const uint8_t *data, | 
| 48 |  |      size_t size ) | 
| 49 | 22.6k | { | 
| 50 | 22.6k |   libbfio_handle_t *file_io_handle                  = NULL; | 
| 51 | 22.6k |   libfsext_extended_attribute_t *extended_attribute = NULL; | 
| 52 | 22.6k |   libfsext_file_entry_t *file_entry                 = NULL; | 
| 53 | 22.6k |   libfsext_volume_t *volume                         = NULL; | 
| 54 | 22.6k |   int number_of_extended_attributes                 = 0; | 
| 55 | 22.6k |   int result                                        = 0; | 
| 56 |  |  | 
| 57 | 22.6k |   if( libbfio_memory_range_initialize( | 
| 58 | 22.6k |        &file_io_handle, | 
| 59 | 22.6k |        NULL ) != 1 ) | 
| 60 | 0 |   { | 
| 61 | 0 |     return( 0 ); | 
| 62 | 0 |   } | 
| 63 | 22.6k |   if( libbfio_memory_range_set( | 
| 64 | 22.6k |        file_io_handle, | 
| 65 | 22.6k |        (uint8_t *) data, | 
| 66 | 22.6k |        size, | 
| 67 | 22.6k |        NULL ) != 1 ) | 
| 68 | 0 |   { | 
| 69 | 0 |     goto on_error_libbfio; | 
| 70 | 0 |   } | 
| 71 | 22.6k |   if( libfsext_volume_initialize( | 
| 72 | 22.6k |        &volume, | 
| 73 | 22.6k |        NULL ) != 1 ) | 
| 74 | 0 |   { | 
| 75 | 0 |     goto on_error_libbfio; | 
| 76 | 0 |   } | 
| 77 | 22.6k |   if( libfsext_volume_open_file_io_handle( | 
| 78 | 22.6k |        volume, | 
| 79 | 22.6k |        file_io_handle, | 
| 80 | 22.6k |        LIBFSEXT_OPEN_READ, | 
| 81 | 22.6k |        NULL ) != 1 ) | 
| 82 | 12.2k |   { | 
| 83 | 12.2k |     goto on_error_libfsext_volume; | 
| 84 | 12.2k |   } | 
| 85 | 10.3k |   result = libfsext_volume_get_file_entry_by_utf8_path( | 
| 86 | 10.3k |             volume, | 
| 87 | 10.3k |             (uint8_t *) "/a_directory/a_file", | 
| 88 | 10.3k |             19, | 
| 89 | 10.3k |             &file_entry, | 
| 90 | 10.3k |             NULL ); | 
| 91 |  |  | 
| 92 | 10.3k |   if( result == 1 ) | 
| 93 | 2.92k |   { | 
| 94 | 2.92k |     if( libfsext_file_entry_get_number_of_extended_attributes( | 
| 95 | 2.92k |          file_entry, | 
| 96 | 2.92k |          &number_of_extended_attributes, | 
| 97 | 2.92k |          NULL ) != 1 ) | 
| 98 | 1.73k |     { | 
| 99 | 1.73k |       goto on_error_libfsext_file_entry; | 
| 100 | 1.73k |     } | 
| 101 | 1.19k |     if( number_of_extended_attributes > 0 ) | 
| 102 | 697 |     { | 
| 103 | 697 |       if( libfsext_file_entry_get_extended_attribute_by_index( | 
| 104 | 697 |            file_entry, | 
| 105 | 697 |            0, | 
| 106 | 697 |            &extended_attribute, | 
| 107 | 697 |            NULL ) != 1 ) | 
| 108 | 189 |       { | 
| 109 | 189 |         goto on_error_libfsext_file_entry; | 
| 110 | 189 |       } | 
| 111 | 508 |       libfsext_extended_attribute_free( | 
| 112 | 508 |        &extended_attribute, | 
| 113 | 508 |        NULL ); | 
| 114 | 508 |     } | 
| 115 | 2.92k | on_error_libfsext_file_entry: | 
| 116 | 2.92k |     libfsext_file_entry_free( | 
| 117 | 2.92k |      &file_entry, | 
| 118 | 2.92k |      NULL ); | 
| 119 | 2.92k |   } | 
| 120 | 10.3k |   libfsext_volume_close( | 
| 121 | 10.3k |    volume, | 
| 122 | 10.3k |    NULL ); | 
| 123 |  |  | 
| 124 | 22.6k | on_error_libfsext_volume: | 
| 125 | 22.6k |   libfsext_volume_free( | 
| 126 | 22.6k |    &volume, | 
| 127 | 22.6k |    NULL ); | 
| 128 |  |  | 
| 129 | 22.6k | on_error_libbfio: | 
| 130 | 22.6k |   libbfio_handle_free( | 
| 131 | 22.6k |    &file_io_handle, | 
| 132 | 22.6k |    NULL ); | 
| 133 |  |  | 
| 134 | 22.6k |   return( 0 ); | 
| 135 | 22.6k | } | 
| 136 |  |  | 
| 137 |  | } /* extern "C" */ | 
| 138 |  |  |