/src/libesedb/ossfuzz/column_fuzzer.cc
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * OSS-Fuzz target for libesedb column type  | 
3  |  |  *  | 
4  |  |  * Copyright (C) 2011-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_libesedb.h"  | 
31  |  |  | 
32  |  | #if !defined( LIBESEDB_HAVE_BFIO )  | 
33  |  |  | 
34  |  | /* Opens a file using a Basic File IO (bfio) handle  | 
35  |  |  * Returns 1 if successful or -1 on error  | 
36  |  |  */  | 
37  |  | LIBESEDB_EXTERN \  | 
38  |  | int libesedb_file_open_file_io_handle(  | 
39  |  |      libesedb_file_t *file,  | 
40  |  |      libbfio_handle_t *file_io_handle,  | 
41  |  |      int access_flags,  | 
42  |  |      libesedb_error_t **error );  | 
43  |  |  | 
44  |  | #endif /* !defined( LIBESEDB_HAVE_BFIO ) */  | 
45  |  |  | 
46  |  | int LLVMFuzzerTestOneInput(  | 
47  |  |      const uint8_t *data,  | 
48  |  |      size_t size )  | 
49  | 1.61k  | { | 
50  | 1.61k  |   libbfio_handle_t *file_io_handle = NULL;  | 
51  | 1.61k  |   libesedb_column_t *column        = NULL;  | 
52  | 1.61k  |   libesedb_file_t *file            = NULL;  | 
53  | 1.61k  |   libesedb_table_t *table          = NULL;  | 
54  | 1.61k  |   int number_of_columns            = 0;  | 
55  | 1.61k  |   int number_of_tables             = 0;  | 
56  |  |  | 
57  | 1.61k  |   if( libbfio_memory_range_initialize(  | 
58  | 1.61k  |        &file_io_handle,  | 
59  | 1.61k  |        NULL ) != 1 )  | 
60  | 0  |   { | 
61  | 0  |     return( 0 );  | 
62  | 0  |   }  | 
63  | 1.61k  |   if( libbfio_memory_range_set(  | 
64  | 1.61k  |        file_io_handle,  | 
65  | 1.61k  |        (uint8_t *) data,  | 
66  | 1.61k  |        size,  | 
67  | 1.61k  |        NULL ) != 1 )  | 
68  | 0  |   { | 
69  | 0  |     goto on_error_libbfio;  | 
70  | 0  |   }  | 
71  | 1.61k  |   if( libesedb_file_initialize(  | 
72  | 1.61k  |        &file,  | 
73  | 1.61k  |        NULL ) != 1 )  | 
74  | 0  |   { | 
75  | 0  |     goto on_error_libbfio;  | 
76  | 0  |   }  | 
77  | 1.61k  |   if( libesedb_file_open_file_io_handle(  | 
78  | 1.61k  |        file,  | 
79  | 1.61k  |        file_io_handle,  | 
80  | 1.61k  |        LIBESEDB_OPEN_READ,  | 
81  | 1.61k  |        NULL ) != 1 )  | 
82  | 1.37k  |   { | 
83  | 1.37k  |     goto on_error_libesedb_file;  | 
84  | 1.37k  |   }  | 
85  | 239  |   if( libesedb_file_get_number_of_tables(  | 
86  | 239  |        file,  | 
87  | 239  |        &number_of_tables,  | 
88  | 239  |        NULL ) != 1 )  | 
89  | 0  |   { | 
90  | 0  |     goto on_error_libesedb_file;  | 
91  | 0  |   }  | 
92  | 239  |   if( number_of_tables > 0 )  | 
93  | 181  |   { | 
94  | 181  |     if( libesedb_file_get_table(  | 
95  | 181  |          file,  | 
96  | 181  |          0,  | 
97  | 181  |          &table,  | 
98  | 181  |          NULL ) == 1 )  | 
99  | 14  |     { | 
100  | 14  |       if( libesedb_table_get_number_of_columns(  | 
101  | 14  |            table,  | 
102  | 14  |            &number_of_columns,  | 
103  | 14  |            0,  | 
104  | 14  |            NULL ) != 1 )  | 
105  | 0  |       { | 
106  | 0  |         goto on_error_libesedb_table;  | 
107  | 0  |       }  | 
108  | 14  |       if( number_of_columns > 0 )  | 
109  | 6  |       { | 
110  | 6  |         if( libesedb_table_get_column(  | 
111  | 6  |              table,  | 
112  | 6  |              0,  | 
113  | 6  |              &column,  | 
114  | 6  |              0,  | 
115  | 6  |              NULL ) == 1 )  | 
116  | 6  |         { | 
117  | 6  |           libesedb_column_free(  | 
118  | 6  |            &column,  | 
119  | 6  |            NULL );  | 
120  | 6  |         }  | 
121  | 6  |       }  | 
122  | 14  | on_error_libesedb_table:  | 
123  | 14  |       libesedb_table_free(  | 
124  | 14  |        &table,  | 
125  | 14  |        NULL );  | 
126  | 14  |     }  | 
127  | 181  |   }  | 
128  | 239  |   libesedb_file_close(  | 
129  | 239  |    file,  | 
130  | 239  |    NULL );  | 
131  |  |  | 
132  | 1.61k  | on_error_libesedb_file:  | 
133  | 1.61k  |   libesedb_file_free(  | 
134  | 1.61k  |    &file,  | 
135  | 1.61k  |    NULL );  | 
136  |  |  | 
137  | 1.61k  | on_error_libbfio:  | 
138  | 1.61k  |   libbfio_handle_free(  | 
139  | 1.61k  |    &file_io_handle,  | 
140  | 1.61k  |    NULL );  | 
141  |  |  | 
142  | 1.61k  |   return( 0 );  | 
143  | 1.61k  | }  | 
144  |  |  | 
145  |  | } /* extern "C" */  | 
146  |  |  |