Skip to content

Commit

Permalink
Applied updates and added column, record and table OSS-Fuzz targets
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed May 8, 2021
1 parent 70fccda commit cffab34
Show file tree
Hide file tree
Showing 7 changed files with 479 additions and 5 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ( 2.59 )

AC_INIT(
[libesedb],
[20210427],
[20210508],
[joachim.metz@gmail.com])

AC_CONFIG_SRCDIR(
Expand Down
65 changes: 64 additions & 1 deletion ossfuzz/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,28 @@ AM_CPPFLAGS = \
@LIBBFIO_CPPFLAGS@

bin_PROGRAMS = \
file_fuzzer
column_fuzzer \
file_fuzzer \
record_fuzzer \
table_fuzzer

column_fuzzer_SOURCES = \
column_fuzzer.cc \
ossfuzz_libbfio.h \
ossfuzz_libesedb.h

column_fuzzer_LDADD = \
@LIB_FUZZING_ENGINE@ \
@LIBBFIO_LIBADD@ \
@LIBCPATH_LIBADD@ \
@LIBCFILE_LIBADD@ \
@LIBUNA_LIBADD@ \
@LIBCDATA_LIBADD@ \
../libesedb/libesedb.la \
@LIBCNOTIFY_LIBADD@ \
@LIBCLOCALE_LIBADD@ \
@LIBCERROR_LIBADD@ \
@LIBINTL@

file_fuzzer_SOURCES = \
file_fuzzer.cc \
Expand All @@ -31,6 +52,42 @@ file_fuzzer_LDADD = \
@LIBCLOCALE_LIBADD@ \
@LIBCERROR_LIBADD@ \
@LIBINTL@

record_fuzzer_SOURCES = \
ossfuzz_libbfio.h \
ossfuzz_libesedb.h \
record_fuzzer.cc

record_fuzzer_LDADD = \
@LIB_FUZZING_ENGINE@ \
@LIBBFIO_LIBADD@ \
@LIBCPATH_LIBADD@ \
@LIBCFILE_LIBADD@ \
@LIBUNA_LIBADD@ \
@LIBCDATA_LIBADD@ \
../libesedb/libesedb.la \
@LIBCNOTIFY_LIBADD@ \
@LIBCLOCALE_LIBADD@ \
@LIBCERROR_LIBADD@ \
@LIBINTL@

table_fuzzer_SOURCES = \
ossfuzz_libbfio.h \
ossfuzz_libesedb.h \
table_fuzzer.cc

table_fuzzer_LDADD = \
@LIB_FUZZING_ENGINE@ \
@LIBBFIO_LIBADD@ \
@LIBCPATH_LIBADD@ \
@LIBCFILE_LIBADD@ \
@LIBUNA_LIBADD@ \
@LIBCDATA_LIBADD@ \
../libesedb/libesedb.la \
@LIBCNOTIFY_LIBADD@ \
@LIBCLOCALE_LIBADD@ \
@LIBCERROR_LIBADD@ \
@LIBINTL@
endif

MAINTAINERCLEANFILES = \
Expand All @@ -40,6 +97,12 @@ distclean: clean
/bin/rm -f Makefile

splint:
@echo "Running splint on column_fuzzer ..."
-splint -preproc -redef $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(column_fuzzer_SOURCES)
@echo "Running splint on file_fuzzer ..."
-splint -preproc -redef $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(file_fuzzer_SOURCES)
@echo "Running splint on record_fuzzer ..."
-splint -preproc -redef $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(record_fuzzer_SOURCES)
@echo "Running splint on table_fuzzer ..."
-splint -preproc -redef $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(table_fuzzer_SOURCES)

146 changes: 146 additions & 0 deletions ossfuzz/column_fuzzer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* OSS-Fuzz target for libesedb column type
*
* Copyright (C) 2011-2020, Joachim Metz <joachim.metz@gmail.com>
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <stddef.h>
#include <stdint.h>

/* Note that some of the OSS-Fuzz engines use C++
*/
extern "C" {

#include "ossfuzz_libbfio.h"
#include "ossfuzz_libesedb.h"

#if !defined( LIBESEDB_HAVE_BFIO )

/* Opens a file using a Basic File IO (bfio) handle
* Returns 1 if successful or -1 on error
*/
LIBESEDB_EXTERN \
int libesedb_file_open_file_io_handle(
libesedb_file_t *file,
libbfio_handle_t *file_io_handle,
int access_flags,
libesedb_error_t **error );

#endif /* !defined( LIBESEDB_HAVE_BFIO ) */

int LLVMFuzzerTestOneInput(
const uint8_t *data,
size_t size )
{
libbfio_handle_t *file_io_handle = NULL;
libesedb_column_t *column = NULL;
libesedb_file_t *file = NULL;
libesedb_table_t *table = NULL;
int number_of_columns = 0;
int number_of_tables = 0;

if( libbfio_memory_range_initialize(
&file_io_handle,
NULL ) != 1 )
{
return( 0 );
}
if( libbfio_memory_range_set(
file_io_handle,
(uint8_t *) data,
size,
NULL ) != 1 )
{
goto on_error_libbfio;
}
if( libesedb_file_initialize(
&file,
NULL ) != 1 )
{
goto on_error_libbfio;
}
if( libesedb_file_open_file_io_handle(
file,
file_io_handle,
LIBESEDB_OPEN_READ,
NULL ) != 1 )
{
goto on_error_libesedb_file;
}
if( libesedb_file_get_number_of_tables(
file,
&number_of_tables,
NULL ) != 1 )
{
goto on_error_libesedb_file;
}
if( number_of_tables > 0 )
{
if( libesedb_file_get_table(
file,
0,
&table,
NULL ) == 1 )
{
if( libesedb_table_get_number_of_columns(
table,
&number_of_columns,
0,
NULL ) != 1 )
{
goto on_error_libesedb_table;
}
if( number_of_columns > 0 )
{
if( libesedb_table_get_column(
table,
0,
&column,
0,
NULL ) == 1 )
{
libesedb_column_free(
&column,
NULL );
}
}
on_error_libesedb_table:
libesedb_table_free(
&table,
NULL );
}
}
libesedb_file_close(
file,
NULL );

on_error_libesedb_file:
libesedb_file_free(
&file,
NULL );

on_error_libbfio:
libbfio_handle_free(
&file_io_handle,
NULL );

return( 0 );
}

} /* extern "C" */

144 changes: 144 additions & 0 deletions ossfuzz/record_fuzzer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* OSS-Fuzz target for libesedb record type
*
* Copyright (C) 2011-2020, Joachim Metz <joachim.metz@gmail.com>
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <stddef.h>
#include <stdint.h>

/* Note that some of the OSS-Fuzz engines use C++
*/
extern "C" {

#include "ossfuzz_libbfio.h"
#include "ossfuzz_libesedb.h"

#if !defined( LIBESEDB_HAVE_BFIO )

/* Opens a file using a Basic File IO (bfio) handle
* Returns 1 if successful or -1 on error
*/
LIBESEDB_EXTERN \
int libesedb_file_open_file_io_handle(
libesedb_file_t *file,
libbfio_handle_t *file_io_handle,
int access_flags,
libesedb_error_t **error );

#endif /* !defined( LIBESEDB_HAVE_BFIO ) */

int LLVMFuzzerTestOneInput(
const uint8_t *data,
size_t size )
{
libbfio_handle_t *file_io_handle = NULL;
libesedb_file_t *file = NULL;
libesedb_record_t *record = NULL;
libesedb_table_t *table = NULL;
int number_of_records = 0;
int number_of_tables = 0;

if( libbfio_memory_range_initialize(
&file_io_handle,
NULL ) != 1 )
{
return( 0 );
}
if( libbfio_memory_range_set(
file_io_handle,
(uint8_t *) data,
size,
NULL ) != 1 )
{
goto on_error_libbfio;
}
if( libesedb_file_initialize(
&file,
NULL ) != 1 )
{
goto on_error_libbfio;
}
if( libesedb_file_open_file_io_handle(
file,
file_io_handle,
LIBESEDB_OPEN_READ,
NULL ) != 1 )
{
goto on_error_libesedb_file;
}
if( libesedb_file_get_number_of_tables(
file,
&number_of_tables,
NULL ) != 1 )
{
goto on_error_libesedb_file;
}
if( number_of_tables > 0 )
{
if( libesedb_file_get_table(
file,
0,
&table,
NULL ) == 1 )
{
if( libesedb_table_get_number_of_records(
table,
&number_of_records,
NULL ) != 1 )
{
goto on_error_libesedb_table;
}
if( number_of_records > 0 )
{
if( libesedb_table_get_record(
table,
0,
&record,
NULL ) == 1 )
{
libesedb_record_free(
&record,
NULL );
}
}
on_error_libesedb_table:
libesedb_table_free(
&table,
NULL );
}
}
libesedb_file_close(
file,
NULL );

on_error_libesedb_file:
libesedb_file_free(
&file,
NULL );

on_error_libbfio:
libbfio_handle_free(
&file_io_handle,
NULL );

return( 0 );
}

} /* extern "C" */

Loading

0 comments on commit cffab34

Please sign in to comment.