int libesedb_checksum_calculate_little_endian_xor32(
     uint32_t *checksum_value,
     const uint8_t *buffer,
     size_t size,
     uint32_t initial_value,
     libcerror_error_t **error )
{
	libesedb_aligned_t *aligned_buffer_iterator = NULL;
	uint8_t *buffer_iterator                    = NULL;
	static char *function                       = "libesedb_checksum_calculate_little_endian_xor32";
	libesedb_aligned_t value_aligned            = 0;
	uint32_t big_endian_value_32bit             = 0;
	uint32_t safe_checksum_value                = 0;
	uint32_t value_32bit                        = 0;
	uint8_t alignment_count                     = 0;
	uint8_t alignment_size                      = 0;
	uint8_t byte_count                          = 0;
	uint8_t byte_order                          = 0;
	uint8_t byte_size                           = 0;

	if( checksum_value == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid checksum value.",
		 function );

		return( -1 );
	}
	if( buffer == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid buffer.",
		 function );

		return( -1 );
	}
	if( size > (size_t) SSIZE_MAX )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
		 "%s: invalid size value exceeds maximum.",
		 function );

		return( -1 );
	}
	safe_checksum_value = initial_value;

	buffer_iterator = (uint8_t *) buffer;

	if( ( ( sizeof( libesedb_aligned_t ) % 4 ) == 0 )
	 && ( size > ( 2 * sizeof( libesedb_aligned_t ) ) ) )
	{

		alignment_size = (uint8_t) ( (intptr_t) buffer_iterator % sizeof( libesedb_aligned_t ) );

		if( alignment_size > 0 )
		{
			byte_size = sizeof( libesedb_aligned_t ) - alignment_size;

			while( byte_size != 0 )
			{
				value_32bit = 0;
				byte_count  = 1;

				if( byte_size >= 4 )
				{
					value_32bit |= buffer_iterator[ 3 ];
					value_32bit <<= 8;

					byte_count++;
				}
				if( byte_size >= 3 )
				{
					value_32bit |= buffer_iterator[ 2 ];
					value_32bit <<= 8;

					byte_count++;
				}
				if( byte_size >= 2 )
				{
					value_32bit |= buffer_iterator[ 1 ];
					value_32bit <<= 8;

					byte_count++;
				}
				value_32bit |= buffer_iterator[ 0 ];

				buffer_iterator += byte_count;
				byte_size       -= byte_count;

				safe_checksum_value ^= value_32bit;
			}
			size -= byte_count;
		}
		aligned_buffer_iterator = (libesedb_aligned_t *) buffer_iterator;

		if( *buffer_iterator != (uint8_t) ( *aligned_buffer_iterator & 0xff ) )
		{
			byte_order = _BYTE_STREAM_ENDIAN_BIG;
		}
		else
		{
			byte_order = _BYTE_STREAM_ENDIAN_LITTLE;
		}

		while( size > sizeof( libesedb_aligned_t ) )
		{
			value_aligned ^= *aligned_buffer_iterator;

			aligned_buffer_iterator++;

			size -= sizeof( libesedb_aligned_t );
		}

		if( alignment_size > 0 )
		{
			byte_count      = ( alignment_size % 4 ) * 8;
			alignment_count = ( sizeof( libesedb_aligned_t ) - alignment_size ) * 8;

			if( byte_order == _BYTE_STREAM_ENDIAN_BIG )
			{

				big_endian_value_32bit = (uint32_t) ( ( value_aligned >> alignment_count ) << byte_count );

				value_32bit = ( ( big_endian_value_32bit & 0x000000ffUL ) << 24 )
				            | ( ( big_endian_value_32bit & 0x0000ff00UL ) << 8 )
				            | ( ( big_endian_value_32bit >> 8 ) & 0x0000ff00UL )
				            | ( ( big_endian_value_32bit >> 24 ) & 0x000000ffUL );

				value_aligned <<= alignment_count;
			}
			else if( byte_order == _BYTE_STREAM_ENDIAN_LITTLE )
			{
				value_32bit = (uint32_t) ( value_aligned << byte_count );

				value_aligned >>= alignment_count;
			}
			safe_checksum_value ^= value_32bit;
		}

		byte_size = (uint8_t) sizeof( libesedb_aligned_t );

		while( byte_size != 0 )
		{
			byte_count = ( ( byte_size / 4 ) - 1 ) * 32;

			if( byte_order == _BYTE_STREAM_ENDIAN_BIG )
			{
				big_endian_value_32bit = (uint32_t) ( ( value_aligned >> byte_count ) & 0xffffffffUL );

				value_32bit = ( ( big_endian_value_32bit & 0x000000ffUL ) << 24 )
				            | ( ( big_endian_value_32bit & 0x0000ff00UL ) << 8 )
				            | ( ( big_endian_value_32bit >> 8 ) & 0x0000ff00UL )
				            | ( ( big_endian_value_32bit >> 24 ) & 0x000000ffUL );
			}
			else if( byte_order == _BYTE_STREAM_ENDIAN_LITTLE )
			{
				value_32bit = (uint32_t) value_aligned;

				value_aligned >>= byte_count;
			}
			byte_size -= 4;

			safe_checksum_value ^= value_32bit;
		}

		buffer_iterator = (uint8_t *) aligned_buffer_iterator;

		byte_size = 4 - ( alignment_size % 4 );

		if( byte_size != 4 )
		{
			value_32bit   = buffer_iterator[ 0 ];
			value_32bit <<= 8;

			if( byte_size >= 2 )
			{
				value_32bit |= buffer_iterator[ 1 ];
			}
			value_32bit <<= 8;

			if( byte_size >= 3 )
			{
				value_32bit |= buffer_iterator[ 2 ];
			}
			value_32bit <<= 8;

			buffer_iterator += byte_size;
			size            -= byte_size;

			safe_checksum_value ^= value_32bit;
		}
	}
	while( size > 0 )
	{
		value_32bit = 0;
		byte_count  = 1;

		if( size >= 4 )
		{
			value_32bit |= buffer_iterator[ 3 ];
			value_32bit <<= 8;

			byte_count++;
		}
		if( size >= 3 )
		{
			value_32bit |= buffer_iterator[ 2 ];
			value_32bit <<= 8;

			byte_count++;
		}
		if( size >= 2 )
		{
			value_32bit |= buffer_iterator[ 1 ];
			value_32bit <<= 8;

			byte_count++;
		}
		value_32bit |= buffer_iterator[ 0 ];

		buffer_iterator += byte_count;
		size            -= byte_count;

		safe_checksum_value ^= value_32bit;
	}
	*checksum_value = safe_checksum_value;

	return( 1 );
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x29c

Cannot access memory at address 0x29c


int libbfio_pool_initialize(
     libbfio_pool_t **pool,
     int number_of_handles,
     int maximum_number_of_open_handles,
     libcerror_error_t **error )
{
	libbfio_internal_pool_t *internal_pool = NULL;
	static char *function                  = "libbfio_pool_initialize";

	if( pool == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid pool.",
		 function );

		return( -1 );
	}
	if( *pool != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid pool value already set.",
		 function );

		return( -1 );
	}
	if( number_of_handles < 0 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO,
		 "%s: invalid number of handles value less than zero.",
		 function );

		return( -1 );
	}
	if( maximum_number_of_open_handles < 0 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_LESS_THAN_ZERO,
		 "%s: invalid maximum number of open handles value less than zero.",
		 function );

		return( -1 );
	}
	internal_pool = memory_allocate_structure(
	                 libbfio_internal_pool_t );

	if( internal_pool == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create pool.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     internal_pool,
	     0,
	     sizeof( libbfio_internal_pool_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear pool.",
		 function );

		memory_free(
		 internal_pool );

		return( -1 );
	}
	if( libcdata_array_initialize(
	     &( internal_pool->handles_array ),
	     number_of_handles,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create handles array.",
		 function );

		goto on_error;
	}
	if( libcdata_list_initialize(
	     &( internal_pool->last_used_list ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create last used list.",
		 function );

		goto on_error;
	}
#if defined( HAVE_MULTI_THREAD_SUPPORT ) && !defined( HAVE_LOCAL_LIBBFIO )
	if( libcthreads_read_write_lock_initialize(
	     &( internal_pool->read_write_lock ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to initialize read/write lock.",
		 function );

		goto on_error;
	}
#endif
	internal_pool->maximum_number_of_open_handles = maximum_number_of_open_handles;
	internal_pool->current_entry                  = -1;

	*pool = (libbfio_pool_t *) internal_pool;

	return( 1 );

on_error:
	if( internal_pool != NULL )
	{
		if( internal_pool->last_used_list != NULL )
		{
			libcdata_list_free(
			 &( internal_pool->last_used_list ),
			 NULL,
			 NULL );
		}
		if( internal_pool->handles_array != NULL )
		{
			libcdata_array_free(
			 &( internal_pool->handles_array ),
			 (int (*)(intptr_t **, libcerror_error_t **)) &libbfio_handle_free,
			 NULL );
		}
		memory_free(
		 internal_pool );
	}
	return( -1 );
}


int libfplist_xml_parser_parse_buffer(
     libfplist_property_list_t *property_list,
     uint8_t *buffer,
     size_t buffer_size,
     libcerror_error_t **error )
{
	libfplist_xml_parser_state_t parser_state;

	YY_BUFFER_STATE buffer_state = NULL;
	static char *function        = "libfplist_xml_parser_parse_buffer";
	int result                   = -1;

	if( buffer == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid buffer.",
		 function );

		return( -1 );
	}
	buffer_state = libfplist_xml_scanner__scan_buffer(
	                (char *) buffer,
	                buffer_size );

	libfplist_xml_scanner_buffer_offset = 0;

	if( buffer_state != NULL )
	{
		parser_state.property_list = property_list;
		parser_state.error         = error;
		parser_state.root_tag      = NULL;
		parser_state.current_tag   = NULL;
		parser_state.parent_tag    = NULL;

		if( libfplist_xml_scanner_parse(
		     &parser_state ) == 0 )
		{
			if( libfplist_property_list_set_root_tag(
			     property_list,
			     parser_state.root_tag,
			     error ) != 1 )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
				 "%s: unable to set root tag.",
				 function );

				result = -1;
			}
			else
			{
				parser_state.root_tag = NULL;

				result = 1;
			}
		}
		libfplist_xml_scanner__delete_buffer(
		 buffer_state );
	}
	libfplist_xml_scanner_lex_destroy();

	if( parser_state.root_tag != NULL )
	{
		libfplist_xml_tag_free(
		 &( parser_state.root_tag ),
		 NULL );
	}
	return( result );
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x1000

Cannot access memory at address 0x1000

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x2

Cannot access memory at address 0x2


int libewf_handle_initialize(
     libewf_handle_t **handle,
     libcerror_error_t **error )
{
	libewf_internal_handle_t *internal_handle = NULL;
	static char *function                     = "libewf_handle_initialize";

	if( handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid handle.",
		 function );

		return( -1 );
	}
	if( *handle != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid handle value already set.",
		 function );

		return( -1 );
	}
	internal_handle = memory_allocate_structure(
	                   libewf_internal_handle_t );

	if( internal_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create handle.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     internal_handle,
	     0,
	     sizeof( libewf_internal_handle_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear handle.",
		 function );

		memory_free(
		 internal_handle );

		return( -1 );
	}
	if( libewf_io_handle_initialize(
	     &( internal_handle->io_handle ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create IO handle.",
		 function );

		goto on_error;
	}
	if( libewf_media_values_initialize(
	     &( internal_handle->media_values ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create media values.",
		 function );

		goto on_error;
	}
	if( libcdata_array_initialize(
	     &( internal_handle->sessions ),
	     0,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create sessions array.",
		 function );

		goto on_error;
	}
	if( libcdata_array_initialize(
	     &( internal_handle->tracks ),
	     0,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create tracks array.",
		 function );

		goto on_error;
	}
	if( libcdata_range_list_initialize(
	     &( internal_handle->acquiry_errors ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create acquiry errors range list.",
		 function );

		goto on_error;
	}
	if( libewf_segment_table_initialize(
	     &( internal_handle->segment_table ),
	     internal_handle->io_handle,
	     LIBEWF_DEFAULT_SEGMENT_FILE_SIZE,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create segment table.",
		 function );

		goto on_error;
	}
#if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT )
	if( libcthreads_read_write_lock_initialize(
	     &( internal_handle->read_write_lock ),
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to initialize read/write lock.",
		 function );

		goto on_error;
	}
#endif
	internal_handle->date_format                    = LIBEWF_DATE_FORMAT_CTIME;
	internal_handle->maximum_number_of_open_handles = LIBBFIO_POOL_UNLIMITED_NUMBER_OF_OPEN_HANDLES;

	*handle = (libewf_handle_t *) internal_handle;

	return( 1 );

on_error:
	if( internal_handle != NULL )
	{
		if( internal_handle->acquiry_errors != NULL )
		{
			libcdata_range_list_free(
			 &( internal_handle->acquiry_errors ),
			 NULL,
			 NULL );
		}
		if( internal_handle->tracks != NULL )
		{
			libcdata_array_free(
			 &( internal_handle->tracks ),
			 NULL,
			 NULL );
		}
		if( internal_handle->sessions != NULL )
		{
			libcdata_array_free(
			 &( internal_handle->sessions ),
			 NULL,
			 NULL );
		}
		if( internal_handle->media_values != NULL )
		{
			libewf_media_values_free(
			 &( internal_handle->media_values ),
			 NULL );
		}
		if( internal_handle->io_handle != NULL )
		{
			libewf_io_handle_free(
			 &( internal_handle->io_handle ),
			 NULL );
		}
		memory_free(
		 internal_handle );
	}
	return( -1 );
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x1

Cannot access memory at address 0x1


int libewf_io_handle_initialize(
     libewf_io_handle_t **io_handle,
     libcerror_error_t **error )
{
	static char *function = "libewf_io_handle_initialize";

	if( io_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid IO handle.",
		 function );

		return( -1 );
	}
	if( *io_handle != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid IO handle value already set.",
		 function );

		return( -1 );
	}
	*io_handle = memory_allocate_structure(
	              libewf_io_handle_t );

	if( *io_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create IO handle.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     *io_handle,
	     0,
	     sizeof( libewf_io_handle_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear IO handle.",
		 function );

		goto on_error;
	}
	( *io_handle )->segment_file_type  = LIBEWF_SEGMENT_FILE_TYPE_UNDEFINED;
	( *io_handle )->format             = LIBEWF_FORMAT_ENCASE6;
	( *io_handle )->major_version      = 1;
	( *io_handle )->minor_version      = 0;
	( *io_handle )->compression_method = LIBEWF_COMPRESSION_METHOD_DEFLATE;
	( *io_handle )->compression_level  = LIBEWF_COMPRESSION_LEVEL_NONE;
	( *io_handle )->zero_on_error      = 1;
	( *io_handle )->header_codepage    = LIBEWF_CODEPAGE_ASCII;

	return( 1 );

on_error:
	if( *io_handle != NULL )
	{
		memory_free(
		 *io_handle );

		*io_handle = NULL;
	}
	return( -1 );
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x840fc08548c08949


int libewf_media_values_initialize(
     libewf_media_values_t **media_values,
     libcerror_error_t **error )
{
	static char *function = "libewf_media_values_initialize";

	if( media_values == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid media values.",
		 function );

		return( -1 );
	}
	if( *media_values != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid media values value already set.",
		 function );

		return( -1 );
	}
	*media_values = memory_allocate_structure(
	                 libewf_media_values_t );

	if( *media_values == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create media values.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     *media_values,
	     0,
	     sizeof( libewf_media_values_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear media values.",
		 function );

		goto on_error;
	}
	( *media_values )->chunk_size        = LIBEWF_MINIMUM_CHUNK_SIZE;
	( *media_values )->sectors_per_chunk = 64;
	( *media_values )->bytes_per_sector  = 512;
	( *media_values )->media_flags       = 0x01;

	return( 1 );

on_error:
	if( *media_values != NULL )
	{
		memory_free(
		 *media_values );

		*media_values = NULL;
	}
	return( -1 );
}


int libfvalue_value_initialize(
     libfvalue_value_t **value,
     const char *type_string,
     const char *type_description,
     libfvalue_data_handle_t *data_handle,
     int (*initialize_instance)(
           intptr_t **instance,
           libcerror_error_t **error ),
     int (*free_instance)(
           intptr_t **instance,
           libcerror_error_t **error ),
     int (*clone_instance)(
           intptr_t **destination_instance,
           intptr_t *source_instance,
           libcerror_error_t **error ),
     int (*copy_from_byte_stream)(
           intptr_t *instance,
           const uint8_t *byte_stream,
           size_t byte_stream_size,
           int encoding,
           libcerror_error_t **error ),
     int (*copy_to_byte_stream)(
           intptr_t *instance,
           uint8_t *byte_stream,
           size_t byte_stream_size,
           int encoding,
           libcerror_error_t **error ),
     int (*copy_from_integer)(
           intptr_t *instance,
           uint64_t integer_value,
           size_t integer_value_size,
           libcerror_error_t **error ),
     int (*copy_to_integer)(
           intptr_t *instance,
           uint64_t *integer_value,
           size_t *integer_value_size,
           libcerror_error_t **error ),
     int (*copy_from_floating_point)(
           intptr_t *instance,
           double floating_point_value,
           size_t floating_point_value_size,
           libcerror_error_t **error ),
     int (*copy_to_floating_point)(
           intptr_t *instance,
           double *floating_point_value,
           size_t *floating_point_value_size,
           libcerror_error_t **error ),
     int (*copy_from_utf8_string_with_index)(
           intptr_t *instance,
           const uint8_t *utf8_string,
           size_t utf8_string_length,
           size_t *utf8_string_index,
           uint32_t string_format_flags,
           libcerror_error_t **error ),
     int (*get_utf8_string_size)(
           intptr_t *instance,
           size_t *utf8_string_size,
           uint32_t string_format_flags,
           libcerror_error_t **error ),
     int (*copy_to_utf8_string_with_index)(
           intptr_t *instance,
           uint8_t *utf8_string,
           size_t utf8_string_size,
           size_t *utf8_string_index,
           uint32_t string_format_flags,
           libcerror_error_t **error ),
     int (*copy_from_utf16_string_with_index)(
           intptr_t *instance,
           const uint16_t *utf16_string,
           size_t utf16_string_length,
           size_t *utf16_string_index,
           uint32_t string_format_flags,
           libcerror_error_t **error ),
     int (*get_utf16_string_size)(
           intptr_t *instance,
           size_t *utf16_string_size,
           uint32_t string_format_flags,
           libcerror_error_t **error ),
     int (*copy_to_utf16_string_with_index)(
           intptr_t *instance,
           uint16_t *utf16_string,
           size_t utf16_string_size,
           size_t *utf16_string_index,
           uint32_t string_format_flags,
           libcerror_error_t **error ),
     int (*copy_from_utf32_string_with_index)(
           intptr_t *instance,
           const uint32_t *utf32_string,
           size_t utf32_string_length,
           size_t *utf32_string_index,
           uint32_t string_format_flags,
           libcerror_error_t **error ),
     int (*get_utf32_string_size)(
           intptr_t *instance,
           size_t *utf32_string_size,
           uint32_t string_format_flags,
           libcerror_error_t **error ),
     int (*copy_to_utf32_string_with_index)(
           intptr_t *instance,
           uint32_t *utf32_string,
           size_t utf32_string_size,
           size_t *utf32_string_index,
           uint32_t string_format_flags,
           libcerror_error_t **error ),
     uint8_t flags,
     libcerror_error_t **error )
{
	libfvalue_internal_value_t *internal_value = NULL;
	static char *function                      = "libfvalue_value_initialize";

	if( value == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid value.",
		 function );

		return( -1 );
	}
	if( *value != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid value value already set.",
		 function );

		return( -1 );
	}
	if( type_string == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid type string",
		 function );

		return( -1 );
	}
	internal_value = memory_allocate_structure(
	                  libfvalue_internal_value_t );

	if( internal_value == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create value.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     internal_value,
	     0,
	     sizeof( libfvalue_internal_value_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear value.",
		 function );

		memory_free(
		 internal_value );

		return( -1 );
	}
	if( free_instance != NULL )
	{
		if( libcdata_array_initialize(
		     &( internal_value->value_instances ),
		     1,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
			 "%s: unable to create value instances array.",
			 function );

			goto on_error;
		}
	}
	if( data_handle == NULL )
	{

		if( libfvalue_data_handle_initialize(
		     &( internal_value->data_handle ),
		     NULL,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
			 "%s: unable to create data handle.",
			 function );

			goto on_error;
		}
		internal_value->flags |= LIBFVALUE_VALUE_FLAG_DATA_HANDLE_MANAGED;
	}
	else
	{
		internal_value->data_handle = data_handle;
	}
	internal_value->type_string                       = type_string;
	internal_value->type_description                  = type_description;

	internal_value->initialize_instance               = initialize_instance;
	internal_value->free_instance                     = free_instance;
	internal_value->clone_instance                    = clone_instance;

	internal_value->copy_from_byte_stream             = copy_from_byte_stream;
	internal_value->copy_to_byte_stream               = copy_to_byte_stream;

	internal_value->copy_from_integer                 = copy_from_integer;
	internal_value->copy_to_integer                   = copy_to_integer;

	internal_value->copy_from_floating_point          = copy_from_floating_point;
	internal_value->copy_to_floating_point            = copy_to_floating_point;

	internal_value->copy_from_utf8_string_with_index  = copy_from_utf8_string_with_index;
	internal_value->get_utf8_string_size              = get_utf8_string_size;
	internal_value->copy_to_utf8_string_with_index    = copy_to_utf8_string_with_index;

	internal_value->copy_from_utf16_string_with_index = copy_from_utf16_string_with_index;
	internal_value->get_utf16_string_size             = get_utf16_string_size;
	internal_value->copy_to_utf16_string_with_index   = copy_to_utf16_string_with_index;

	internal_value->copy_from_utf32_string_with_index = copy_from_utf32_string_with_index;
	internal_value->get_utf32_string_size             = get_utf32_string_size;
	internal_value->copy_to_utf32_string_with_index   = copy_to_utf32_string_with_index;

	internal_value->flags                            |= flags;

	*value = (libfvalue_value_t *) internal_value;

	return( 1 );

on_error:
	if( internal_value != NULL )
	{
		if( internal_value->value_instances != NULL )
		{
			libcdata_array_free(
			 &( internal_value->value_instances ),
			 NULL,
			 NULL );
		}
		memory_free(
		 internal_value );
	}
	return( -1 );
}

{int (intptr_t *, size_t *, uint32_t, libcerror_error_t **)} 0x6882c0 <libfvalue_string_get_utf32_string_size>


int libewf_segment_file_initialize(
     libewf_segment_file_t **segment_file,
     libewf_io_handle_t *io_handle,
     libcerror_error_t **error )
{
	static char *function = "libewf_segment_file_initialize";

	if( segment_file == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid segment file.",
		 function );

		return( -1 );
	}
	if( *segment_file != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid segment file value already set.",
		 function );

		return( -1 );
	}
	if( io_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid IO handle.",
		 function );

		return( -1 );
	}
	*segment_file = memory_allocate_structure(
	                 libewf_segment_file_t );

	if( *segment_file == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create segment file.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     *segment_file,
	     0,
	     sizeof( libewf_segment_file_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear segment file.",
		 function );

		memory_free(
		 *segment_file );

		*segment_file = NULL;

		return( -1 );
	}
	if( libfdata_list_initialize(
	     &( ( *segment_file )->sections_list ),
	     (intptr_t *) *segment_file,
	     NULL,
	     NULL,
	     (int (*)(intptr_t *, intptr_t *, libfdata_list_element_t *, libfdata_cache_t *, int, off64_t, size64_t, uint32_t, uint8_t, libcerror_error_t **)) &libewf_segment_file_read_section_element_data,
	     NULL,
	     LIBFDATA_DATA_HANDLE_FLAG_NON_MANAGED,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create sections list.",
		 function );

		goto on_error;
	}
	if( libfdata_list_initialize(
	     &( ( *segment_file )->chunk_groups_list ),
	     (intptr_t *) *segment_file,
	     NULL,
	     NULL,
	     (int (*)(intptr_t *, intptr_t *, libfdata_list_element_t *, libfdata_cache_t *, int, off64_t, size64_t, uint32_t, uint8_t, libcerror_error_t **)) &libewf_segment_file_read_chunk_group_element_data,
	     NULL,
	     LIBFDATA_DATA_HANDLE_FLAG_NON_MANAGED,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create chunk groups list.",
		 function );

		goto on_error;
	}
	if( libfcache_cache_initialize(
	     &( ( *segment_file )->chunk_groups_cache ),
	     LIBEWF_MAXIMUM_CACHE_ENTRIES_CHUNK_GROUPS,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create chunk groups cache.",
		 function );

		goto on_error;
	}
	( *segment_file )->io_handle                        = io_handle;
	( *segment_file )->device_information_section_index = -1;
	( *segment_file )->previous_last_chunk_filled       = -1;
	( *segment_file )->last_chunk_filled                = -1;
	( *segment_file )->last_chunk_compared              = -1;

	return( 1 );

on_error:
	if( *segment_file != NULL )
	{
		if( ( *segment_file )->chunk_groups_list != NULL )
		{
			libfdata_list_free(
			 &( ( *segment_file )->chunk_groups_list ),
			 NULL );
		}
		if( ( *segment_file )->sections_list != NULL )
		{
			libfdata_list_free(
			 &( ( *segment_file )->sections_list ),
			 NULL );
		}
		memory_free(
		 *segment_file );

		*segment_file = NULL;
	}
	return( -1 );
}

Cannot access memory at address 0x1


int libfsfat_block_tree_node_initialize(
     libfsfat_block_tree_node_t **block_tree_node,
     off64_t offset,
     size64_t size,
     size64_t leaf_value_size,
     libcerror_error_t **error )
{
	static char *function  = "libfsfat_block_tree_node_initialize";
	size64_t sub_node_size = 0;

	if( block_tree_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid block tree node.",
		 function );

		return( -1 );
	}
	if( *block_tree_node != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid block tree node value already set.",
		 function );

		return( -1 );
	}
	if( offset < 0 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
		 "%s: invalid offset value out of bounds.",
		 function );

		return( -1 );
	}
	if( ( size == 0 )
	 || ( size > (size64_t) ( INT64_MAX - offset ) ) )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
		 "%s: invalid size value out of bounds.",
		 function );

		return( -1 );
	}
	if( leaf_value_size == 0 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
		 "%s: invalid leaf value size value out of bounds.",
		 function );

		return( -1 );
	}
	*block_tree_node = memory_allocate_structure(
	                    libfsfat_block_tree_node_t );

	if( *block_tree_node == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create block tree node.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     *block_tree_node,
	     0,
	     sizeof( libfsfat_block_tree_node_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear block tree node.",
		 function );

		memory_free(
		 *block_tree_node );

		*block_tree_node = NULL;

		return( -1 );
	}
	if( libcdata_array_initialize(
	     &( ( *block_tree_node )->sub_nodes_array ),
	     LIBFSFAT_BLOCK_TREE_NUMBER_OF_SUB_NODES,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create sub nodes array.",
		 function );

		goto on_error;
	}
	sub_node_size = leaf_value_size;

	while( ( size / sub_node_size ) > LIBFSFAT_BLOCK_TREE_NUMBER_OF_SUB_NODES )
	{
		sub_node_size *= LIBFSFAT_BLOCK_TREE_NUMBER_OF_SUB_NODES;
	}
	( *block_tree_node )->start_offset  = offset;
	( *block_tree_node )->end_offset    = offset + size;
	( *block_tree_node )->size          = size;
	( *block_tree_node )->sub_node_size = sub_node_size;

	if( sub_node_size == leaf_value_size )
	{
		( *block_tree_node )->is_leaf_node = 1;
	}
	return( 1 );

on_error:
	if( *block_tree_node != NULL )
	{
		memory_free(
		 *block_tree_node );

		*block_tree_node = NULL;
	}
	return( -1 );
}

( *block_tree_node )->size          = size;

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x204

Cannot access memory at address 0x204


int libexe_io_handle_initialize(
     libexe_io_handle_t **io_handle,
     libcerror_error_t **error )
{
	static char *function = "libexe_io_handle_initialize";

	if( io_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid IO handle.",
		 function );

		return( -1 );
	}
	if( *io_handle != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid IO handle value already set.",
		 function );

		return( -1 );
	}
	*io_handle = memory_allocate_structure(
	              libexe_io_handle_t );

	if( *io_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create IO handle.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     *io_handle,
	     0,
	     sizeof( libexe_io_handle_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear file.",
		 function );

		memory_free(
		 *io_handle );

		*io_handle = NULL;

		return( -1 );
	}
	( *io_handle )->executable_type = LIBEXE_EXECUTABLE_TYPE_MZ;
	( *io_handle )->ascii_codepage  = LIBEXE_CODEPAGE_WINDOWS_1252;

	return( 1 );

on_error:
	if( *io_handle != NULL )
	{
		memory_free(
		 *io_handle );

		*io_handle = NULL;
	}
	return( -1 );
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x40ec8348e5894855

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x230

Cannot access memory at address 0x230


int libfdata_stream_initialize(
     libfdata_stream_t **stream,
     intptr_t *data_handle,
     int (*free_data_handle)(
            intptr_t **data_handle,
            libcerror_error_t **error ),
     int (*clone_data_handle)(
            intptr_t **destination_data_handle,
            intptr_t *source_data_handle,
            libcerror_error_t **error ),
     int (*create_segment)(
            intptr_t *data_handle,
            intptr_t *file_io_handle,
            int segment_index,
            int *segment_file_index,
            off64_t *segment_offset,
            size64_t *segment_size,
            uint32_t *segment_flags,
            libcerror_error_t **error ),
     ssize_t (*read_segment_data)(
                intptr_t *data_handle,
                intptr_t *file_io_handle,
                int segment_index,
                int segment_file_index,
                uint8_t *segment_data,
                size_t segment_data_size,
                uint32_t segment_flags,
                uint8_t read_flags,
                libcerror_error_t **error ),
     ssize_t (*write_segment_data)(
                intptr_t *data_handle,
                intptr_t *file_io_handle,
                int segment_index,
                int segment_file_index,
                const uint8_t *segment_data,
                size_t segment_data_size,
                uint32_t segment_flags,
                uint8_t write_flags,
                libcerror_error_t **error ),
     off64_t (*seek_segment_offset)(
                intptr_t *data_handle,
                intptr_t *file_io_handle,
                int segment_index,
                int segment_file_index,
                off64_t segment_offset,
                libcerror_error_t **error ),
     uint8_t flags,
     libcerror_error_t **error )
{
	libfdata_internal_stream_t *internal_stream = NULL;
	static char *function                       = "libfdata_stream_initialize";

	if( stream == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid stream.",
		 function );

		return( -1 );
	}
	if( *stream != NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
		 "%s: invalid stream value already set.",
		 function );

		return( -1 );
	}
	if( ( flags & 0xfe ) != 0 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
		 "%s: unsupported flags: 0x%02" PRIx8 ".",
		 function );

		return( -1 );
	}
	internal_stream = memory_allocate_structure(
	                   libfdata_internal_stream_t );

	if( internal_stream == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
		 "%s: unable to create stream.",
		 function );

		goto on_error;
	}
	if( memory_set(
	     internal_stream,
	     0,
	     sizeof( libfdata_internal_stream_t ) ) == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_MEMORY,
		 LIBCERROR_MEMORY_ERROR_SET_FAILED,
		 "%s: unable to clear stream.",
		 function );

		memory_free(
		 internal_stream );

		return( -1 );
	}
	if( libcdata_array_initialize(
	     &( internal_stream->segments_array ),
	     0,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create segments array.",
		 function );

		goto on_error;
	}
	if( libcdata_array_initialize(
	     &( internal_stream->mapped_ranges_array ),
	     0,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create mapped ranges array.",
		 function );

		goto on_error;
	}
	internal_stream->segment_offset      = -1;
	internal_stream->flags              |= flags;
	internal_stream->data_handle         = data_handle;
	internal_stream->free_data_handle    = free_data_handle;
	internal_stream->clone_data_handle   = clone_data_handle;
	internal_stream->create_segment      = create_segment;
	internal_stream->read_segment_data   = read_segment_data;
	internal_stream->write_segment_data  = write_segment_data;
	internal_stream->seek_segment_offset = seek_segment_offset;

	*stream = (libfdata_stream_t *) internal_stream;

	return( 1 );

on_error:
	if( internal_stream != NULL )
	{
		if( internal_stream->segments_array != NULL )
		{
			libcdata_array_free(
			 &( internal_stream->segments_array ),
			 NULL,
			 NULL );
		}
		memory_free(
		 internal_stream );
	}
	return( -1 );
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x5b0000006e


int libagdb_compressed_blocks_stream_initialize(
     libfdata_stream_t **compressed_blocks_stream,
     libfdata_list_t *compressed_blocks_list,
     libfcache_cache_t *compressed_blocks_cache,
     libcerror_error_t **error )
{
	libagdb_compressed_blocks_stream_data_handle_t *data_handle = NULL;
	static char *function                                       = "libagdb_compressed_blocks_stream_initialize";
	off64_t segment_offset                                      = 0;
	size64_t segment_size                                       = 0;
	int element_index                                           = 0;
	int number_of_elements                                      = 0;
	int segment_index                                           = 0;

	if( compressed_blocks_stream == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid compressed block stream.",
		 function );

		return( -1 );
	}
	if( compressed_blocks_list == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid compressed blocks list.",
		 function );

		return( -1 );
	}
	if( libagdb_compressed_blocks_stream_data_handle_initialize(
	     &data_handle,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create data handle.",
		 function );

		goto on_error;
	}
	if( data_handle == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
		 "%s: missing data handle.",
		 function );

		goto on_error;
	}
	data_handle->compressed_blocks_list  = compressed_blocks_list;
	data_handle->compressed_blocks_cache = compressed_blocks_cache;

	if( libfdata_stream_initialize(
	     compressed_blocks_stream,
	     (intptr_t *) data_handle,
	     (int (*)(intptr_t **, libcerror_error_t **)) &libagdb_compressed_blocks_stream_data_handle_free,
	     NULL,
	     NULL,
	     (ssize_t (*)(intptr_t *, intptr_t *, int, int, uint8_t *, size_t, uint32_t, uint8_t, libcerror_error_t **)) &libagdb_compressed_blocks_stream_data_handle_read_segment_data,
	     NULL,
	     (off64_t (*)(intptr_t *, intptr_t *, int, int, off64_t, libcerror_error_t **)) &libagdb_compressed_blocks_stream_data_handle_seek_segment_offset,
	     LIBFDATA_DATA_HANDLE_FLAG_MANAGED,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
		 "%s: unable to create stream.",
		 function );

		goto on_error;
	}
	if( libfdata_list_get_number_of_elements(
	     compressed_blocks_list,
	     &number_of_elements,
	     error ) != 1 )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
		 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
		 "%s: unable to retrieve number of compressed blocks list elements.",
		 function );

		data_handle = NULL;

		goto on_error;
	}
	for( element_index = 0;
	     element_index < number_of_elements;
	     element_index++ )
	{
		if( libfdata_list_get_mapped_size_by_index(
		     compressed_blocks_list,
		     element_index,
		     &segment_size,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
			 "%s: unable to retrieve compressed blocks list element: %d mapped size.",
			 function,
			 element_index );

			data_handle = NULL;

			goto on_error;
		}
		if( libfdata_stream_append_segment(
		     *compressed_blocks_stream,
		     &segment_index,
		     0,
		     segment_offset,
		     segment_size,
		     0,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
			 "%s: unable to append compressed blocks stream segment: %d.",
			 function,
			 element_index );

			data_handle = NULL;

			goto on_error;
		}
		segment_offset += segment_size;
	}
	return( 1 );

on_error:
	if( *compressed_blocks_stream != NULL )
	{
		libfdata_stream_free(
		 compressed_blocks_stream,
		 NULL );
	}
	if( data_handle != NULL )
	{
		libagdb_compressed_blocks_stream_data_handle_free(
		 &data_handle,
		 NULL );
	}
	return( -1 );
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x801087060


void
init_parse_tree(struct sudoers_parse_tree *parse_tree, char *lhost, char *shost,
    struct sudoers_context *ctx, struct sudo_nss *nss)
{
    TAILQ_INIT(&parse_tree->userspecs);
    TAILQ_INIT(&parse_tree->defaults);
    parse_tree->aliases = NULL;
    parse_tree->shost = shost;
    parse_tree->lhost = lhost;
    parse_tree->ctx = ctx;
    parse_tree->nss = nss;
}


size_t
strlcpy(char *dst, const char *src, size_t size) {
	char *d = dst;
	const char *s = src;
	size_t n = size;

	if (n != 0U && --n != 0U) {
		do {
			if ((*d++ = *s++) == 0) {
				break;
			}
		} while (--n != 0U);
	}

	if (n == 0U) {
		if (size != 0U) {
			*d = '\0';
		}
		while (*s++) {
		}
	}

	return (s - src - 1);
}


void
dns_message_create(isc_mem_t *mctx, isc_mempool_t *namepool,
		   isc_mempool_t *rdspool, dns_message_intent_t intent,
		   dns_message_t **msgp) {
	REQUIRE(mctx != NULL);
	REQUIRE(msgp != NULL);
	REQUIRE(*msgp == NULL);
	REQUIRE(intent == DNS_MESSAGE_INTENTPARSE ||
		intent == DNS_MESSAGE_INTENTRENDER);
	REQUIRE((namepool != NULL && rdspool != NULL) ||
		(namepool == NULL && rdspool == NULL));

	dns_message_t *msg = isc_mem_get(mctx, sizeof(dns_message_t));
	*msg = (dns_message_t){
		.from_to_wire = intent,
		.references = ISC_REFCOUNT_INITIALIZER(1),
		.scratchpad = ISC_LIST_INITIALIZER,
		.cleanup = ISC_LIST_INITIALIZER,
		.rdatas = ISC_LIST_INITIALIZER,
		.rdatalists = ISC_LIST_INITIALIZER,
		.offsets = ISC_LIST_INITIALIZER,
		.freerdata = ISC_LIST_INITIALIZER,
		.freerdatalist = ISC_LIST_INITIALIZER,
		.magic = DNS_MESSAGE_MAGIC,
		.namepool = namepool,
		.rdspool = rdspool,
		.free_pools = (namepool == NULL && rdspool == NULL),
	};

	isc_mem_attach(mctx, &msg->mctx);

	if (msg->free_pools) {
		dns_message_createpools(mctx, &msg->namepool, &msg->rdspool);
	}

	msginit(msg);

	for (size_t i = 0; i < DNS_SECTION_MAX; i++) {
		ISC_LIST_INIT(msg->sections[i]);
	}

	isc_buffer_t *dynbuf = NULL;
	isc_buffer_allocate(mctx, &dynbuf, SCRATCHPAD_SIZE);
	ISC_LIST_APPEND(msg->scratchpad, dynbuf, link);

	*msgp = msg;
}


size_t
dns_qpkey_fromname(dns_qpkey_t key, const dns_name_t *name) {
	size_t len, label;
	dns_fixedname_t fixed;

	REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC));

	if (name->labels == 0) {
		key[0] = SHIFT_NOBYTE;
		return (0);
	}

	if (name->offsets == NULL) {
		dns_name_t *clone = dns_fixedname_initname(&fixed);
		dns_name_clone(name, clone);
		name = clone;
	}

	len = 0;
	label = name->labels;
	while (label-- > 0) {
		const uint8_t *ldata = name->ndata + name->offsets[label];
		size_t label_len = *ldata++;
		while (label_len-- > 0) {
			uint16_t bits = dns_qp_bits_for_byte[*ldata++];
			key[len++] = bits & 0xFF;
			if ((bits >> 8) != 0) {
				key[len++] = bits >> 8;
			}
		}

		key[len++] = SHIFT_NOBYTE;
	}

	key[len] = SHIFT_NOBYTE;
	ENSURE(len < sizeof(dns_qpkey_t));
	return (len);
}


isc_result_t
isc_parse_uint32(uint32_t *uip, const char *string, int base) {
	unsigned long n;
	uint32_t r;
	char *e;
	if (!isalnum((unsigned char)(string[0]))) {
		return (ISC_R_BADNUMBER);
	}
	errno = 0;
	n = strtoul(string, &e, base);
	if (*e != '\0') {
		return (ISC_R_BADNUMBER);
	}

	r = (uint32_t)n;
	if ((n == ULONG_MAX && errno == ERANGE) || (n != (unsigned long)r)) {
		return (ISC_R_RANGE);
	}
	*uip = r;
	return (ISC_R_SUCCESS);
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0xffffffff00000000


int
_dwarf_macho_setup(int fd,
    char *true_path,
    unsigned universalnumber,
    unsigned ftype,
    unsigned endian,
    unsigned offsetsize,
    Dwarf_Unsigned filesize,
    unsigned groupnumber,
    Dwarf_Handler errhand,
    Dwarf_Ptr errarg,
    Dwarf_Debug *dbg,Dwarf_Error *error)
{
    Dwarf_Obj_Access_Interface_a *binary_interface = 0;
    dwarf_macho_object_access_internals_t *intfc = 0;
    int res = DW_DLV_OK;
    int localerrnum = 0;
    unsigned universalbinary_count = 0;

    res = _dwarf_macho_object_access_init(
        fd,
        universalnumber,
        ftype,endian,offsetsize,
        &universalbinary_count,
        filesize,
        &binary_interface,
        &localerrnum);
    if (res != DW_DLV_OK) {
        if (res == DW_DLV_NO_ENTRY) {
            return res;
        }
        _dwarf_error(NULL, error, localerrnum);
        return DW_DLV_ERROR;
    }

    res = dwarf_object_init_b(binary_interface, errhand, errarg,
        groupnumber, dbg, error);
    if (res != DW_DLV_OK){
        _dwarf_destruct_macho_access(binary_interface);
        return res;
    }
    intfc = binary_interface->ai_object;
    intfc->mo_path = strdup(true_path);
    (*dbg)->de_obj_flags = intfc->mo_flags;
    (*dbg)->de_obj_machine = intfc->mo_machine;
    (*dbg)->de_universalbinary_index = universalnumber;
    (*dbg)->de_universalbinary_count = universalbinary_count;
    return res;
}


int
_dwarf_elf_nlsetup(int fd,
    char *true_path,
    unsigned ftype,
    unsigned endian,
    unsigned offsetsize,
    size_t filesize,
    unsigned groupnumber,
    Dwarf_Handler errhand,
    Dwarf_Ptr errarg,
    Dwarf_Debug *dbg,Dwarf_Error *error)
{
    Dwarf_Obj_Access_Interface_a *binary_interface = 0;
    dwarf_elf_object_access_internals_t *intfc = 0;
    int res = DW_DLV_OK;
    int localerrnum = 0;

    res = _dwarf_elf_object_access_init(
        fd,
        ftype,endian,offsetsize,filesize,
        &binary_interface,
        &localerrnum);
    if (res != DW_DLV_OK) {
        if (res == DW_DLV_NO_ENTRY) {
            return res;
        }
        _dwarf_error(NULL, error, localerrnum);
        return DW_DLV_ERROR;
    }

    res = dwarf_object_init_b(binary_interface, errhand, errarg,
        groupnumber, dbg, error);
    if (res != DW_DLV_OK){
        _dwarf_destruct_elf_nlaccess(binary_interface);
        return res;
    }
    intfc = binary_interface->ai_object;
    intfc->f_path = strdup(true_path);
    (*dbg)->de_obj_machine = intfc->f_machine;
    (*dbg)->de_obj_flags = intfc->f_flags;
    return res;
}


static int look_for_our_target(Dwarf_Debug dbg, struct target_data_s *td,
                               Dwarf_Error *errp) {
  Dwarf_Unsigned cu_header_length = 0;
  Dwarf_Unsigned abbrev_offset = 0;
  Dwarf_Half address_size = 0;
  Dwarf_Half version_stamp = 0;
  Dwarf_Half offset_size = 0;
  Dwarf_Half extension_size = 0;
  Dwarf_Unsigned typeoffset = 0;
  Dwarf_Half header_cu_type = unittype;
  Dwarf_Bool is_info = g_is_info;
  int cu_number = 0;

  for (;; ++cu_number) {
    Dwarf_Die no_die = 0;
    Dwarf_Die cu_die = 0;
    int res = DW_DLV_ERROR;
    Dwarf_Sig8 signature;

    memset(&signature, 0, sizeof(signature));
    res = dwarf_next_cu_header_d(dbg, is_info, &cu_header_length,
                                 &version_stamp, &abbrev_offset, &address_size,
                                 &offset_size, &extension_size, &signature,
                                 &typeoffset, 0, &header_cu_type, errp);
    if (res == DW_DLV_ERROR) {
      if (errp) {
        char *em = dwarf_errmsg(*errp);
      }
      return DW_DLV_NO_ENTRY;
    }
    if (res == DW_DLV_NO_ENTRY) {
      return DW_DLV_NO_ENTRY;
    }
    cu_version_stamp = version_stamp;
    cu_offset_size = offset_size;
    res = dwarf_siblingof_b(dbg, no_die, is_info, &cu_die, errp);
    if (res == DW_DLV_ERROR) {
      if (errp) {
        char *em = dwarf_errmsg(*errp);
      }
      return res;
    }
    if (res == DW_DLV_NO_ENTRY) {
      return res;
    }

    td->td_cu_die = cu_die;
    res = get_die_and_siblings(dbg, cu_die, is_info, 0, cu_number, td, errp);
    if (res == FOUND_SUBPROG) {
      read_line_data(dbg, td, errp);
      if (td->td_reportallfound) {
        return res;
      }
      return res;
    } else if (res == IN_THIS_CU) {
      if (errp) {
          char *em = dwarf_errmsg(*errp);
      }
      return res;
    } else if (res == DW_DLV_ERROR) {
      if (errp) {
        char *em = dwarf_errmsg(*errp);
      }
      return DW_DLV_ERROR;
    }
    return DW_DLV_NO_ENTRY;
  }
}


int dwarf_load_rnglists(
    Dwarf_Debug dbg,
    Dwarf_Unsigned *rnglists_count,
    Dwarf_Error *error)
{
    int res = DW_DLV_ERROR;
    Dwarf_Rnglists_Context *cxt = 0;
    Dwarf_Unsigned count = 0;

    CHECK_DBG(dbg,error,"dwarf_load_rnglists");
    if (dbg->de_rnglists_context) {
        if (rnglists_count) {
            *rnglists_count = dbg->de_rnglists_context_count;
        }
        return DW_DLV_OK;
    }
    if (!dbg->de_debug_rnglists.dss_size) {

        return DW_DLV_NO_ENTRY;
    }
    if (!dbg->de_debug_rnglists.dss_data) {
        res = _dwarf_load_section(dbg, &dbg->de_debug_rnglists,
            error);
        if (res != DW_DLV_OK) {
            return res;
        }
    }
    res = internal_load_rnglists_contexts(dbg,&cxt,&count,error);
    if (res == DW_DLV_ERROR) {
        return res;
    }
    dbg->de_rnglists_context = cxt;
    dbg->de_rnglists_context_count = count;
    if (rnglists_count) {
        *rnglists_count = count;
    }
    return DW_DLV_OK;
}


int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
  l_uint32 oldnCcalls = L->nCcalls;
  struct lua_longjmp lj;
  lj.status = LUA_OK;
  lj.previous = L->errorJmp;
  L->errorJmp = &lj;
  LUAI_TRY(L, &lj,
    (*f)(L, ud);
  );
  L->errorJmp = lj.previous;
  L->nCcalls = oldnCcalls;
  return lj.status;
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x3000000040


void test_deflate(unsigned char *compr, size_t comprLen)
{
    z_stream c_stream;
    int err;
    unsigned long len = dataLen;

    c_stream.zalloc = zalloc;
    c_stream.zfree = zfree;
    c_stream.opaque = NULL;

    err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
    CHECK_ERR(err, "deflateInit");

    c_stream.next_in = (Bytef *)data;
    c_stream.next_out = compr;

    while (c_stream.total_in != len && c_stream.total_out < comprLen)
    {
        c_stream.avail_in = c_stream.avail_out = 1;
        err = deflate(&c_stream, Z_NO_FLUSH);
        CHECK_ERR(err, "deflate small 1");
    }

    for (;;)
    {
        c_stream.avail_out = 1;
        err = deflate(&c_stream, Z_FINISH);
        if (err == Z_STREAM_END)
            break;
        CHECK_ERR(err, "deflate small 2");
    }

    err = deflateEnd(&c_stream);
    CHECK_ERR(err, "deflateEnd");
}


void test_large_deflate(unsigned char *compr, size_t comprLen,
                        unsigned char *uncompr, size_t uncomprLen)
{
    z_stream c_stream;
    int err;

    c_stream.zalloc = zalloc;
    c_stream.zfree = zfree;
    c_stream.opaque = NULL;

    err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
    CHECK_ERR(err, "deflateInit");

    c_stream.next_out = compr;
    c_stream.avail_out = (unsigned int)comprLen;

    c_stream.next_in = uncompr;
    c_stream.avail_in = (unsigned int)uncomprLen;
    err = deflate(&c_stream, Z_NO_FLUSH);
    CHECK_ERR(err, "deflate large 1");

    if (c_stream.avail_in != 0)
    {
        fprintf(stderr, "deflate not greedy\n");
        exit(1);
    }

    c_stream.next_in = compr;
    diff = (unsigned int)(c_stream.next_out - compr);
    c_stream.avail_in = diff;

    deflate(&c_stream, Z_NO_FLUSH);
    err = deflate(&c_stream, Z_FINISH);

    if (err != Z_STREAM_END)
    {
        fprintf(stderr, "deflate large should report Z_STREAM_END\n");
        exit(1);
    }
    err = deflateEnd(&c_stream);
    CHECK_ERR(err, "deflateEnd");
}

0x1 <error: Cannot access memory at address 0x1>


void test_flush(unsigned char *compr, size_t *comprLen)
{
    z_stream c_stream;
    int err;
    unsigned int len = dataLen;

    c_stream.zalloc = zalloc;
    c_stream.zfree = zfree;
    c_stream.opaque = NULL;

    err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
    CHECK_ERR(err, "deflateInit");

    c_stream.next_in = (Bytef *)data;
    c_stream.next_out = compr;
    c_stream.avail_in = 3;
    c_stream.avail_out = (unsigned int)*comprLen;
    err = deflate(&c_stream, Z_FULL_FLUSH);
    CHECK_ERR(err, "deflate flush 1");

    compr[3]++;
    c_stream.avail_in = len - 3;

    err = deflate(&c_stream, Z_FINISH);

    if (err != Z_STREAM_END)
    {
        CHECK_ERR(err, "deflate flush 2");
    }

    err = deflateEnd(&c_stream);
    CHECK_ERR(err, "deflateEnd");

    *comprLen = (size_t)c_stream.total_out;
}


void EXPORT_CALL
lou_registerLogCallback(logcallback callback) {
	if (callback == NULL)
		logCallbackFunction = defaultLogCallback;
	else
		logCallbackFunction = callback;
}


void ByteStream_init(struct ByteStream *bs, const uint8_t *data, size_t size) {
  bs->data_ = data;
  bs->size_ = size;
  bs->pos_ = 0;
}


void
sldns_buffer_init_frm_data(sldns_buffer *buffer, void *data, size_t size)
{
	memset(buffer, 0, sizeof(*buffer));
	buffer->_data = data;
	buffer->_capacity = buffer->_limit = size;
	buffer->_fixed = 1;
}


void
log_init(const char* filename, int use_syslog, const char* chrootdir)
{
	FILE *f;
	if(!key_created) {
		key_created = 1;
		ub_thread_key_create(&logkey, NULL);
		lock_basic_init(&log_lock);
	}
	lock_basic_lock(&log_lock);
	if(logfile
#if defined(HAVE_SYSLOG_H) || defined(UB_ON_WINDOWS)
	|| logging_to_syslog
#endif
	) {
		lock_basic_unlock(&log_lock);
		verbose(VERB_QUERY, "switching log to %s",
			use_syslog?"syslog":(filename&&filename[0]?filename:"stderr"));
		lock_basic_lock(&log_lock);
	}
	if(logfile && logfile != stderr) {
		FILE* cl = logfile;
		logfile = NULL;
		fclose(cl);
	}
#ifdef HAVE_SYSLOG_H
	if(logging_to_syslog) {
		closelog();
		logging_to_syslog = 0;
	}
	if(use_syslog) {

		openlog(ident, LOG_NDELAY, UB_SYSLOG_FACILITY);
		logging_to_syslog = 1;
		lock_basic_unlock(&log_lock);
		return;
	}
#elif defined(UB_ON_WINDOWS)
	if(logging_to_syslog) {
		logging_to_syslog = 0;
	}
	if(use_syslog) {
		logging_to_syslog = 1;
		lock_basic_unlock(&log_lock);
		return;
	}
#endif
	if(!filename || !filename[0]) {
		logfile = stderr;
		lock_basic_unlock(&log_lock);
		return;
	}

	if(chrootdir && chrootdir[0] && strncmp(filename, chrootdir,
		strlen(chrootdir)) == 0)
		filename += strlen(chrootdir);
	f = fopen(filename, "a");
	if(!f) {
		lock_basic_unlock(&log_lock);
		log_err("Could not open logfile %s: %s", filename,
			strerror(errno));
		return;
	}
#ifndef UB_ON_WINDOWS

	setvbuf(f, NULL, (int)_IOLBF, 0);
#endif
	logfile = f;
	lock_basic_unlock(&log_lock);
}

0x1ee000 <error: Cannot access memory at address 0x1ee000>

0x1f1660 <error: Cannot access memory at address 0x1f1660>


void fuzzinit(Fuzzer *fuzzer){
    struct sockaddr_in server_addr;
    fuzzer->socket = socket(AF_INET, SOCK_STREAM, 0);

    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(fuzzer->port);
    server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");

    setsockopt(fuzzer->socket, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int));

    bind(fuzzer->socket, (struct sockaddr*)&server_addr, sizeof(server_addr));
    listen(fuzzer->socket,1);
}


int Parser_LoadDocument(

	IXML_Document **retDoc,

	const char *xmlFileName,

	int file)
{
	int rc = IXML_SUCCESS;
	Parser *xmlParser = NULL;

	xmlParser = Parser_init();
	if (xmlParser == NULL) {
		return IXML_INSUFFICIENT_MEMORY;
	}

	rc = Parser_readFileOrBuffer(xmlParser, xmlFileName, file);
	if (rc != IXML_SUCCESS) {
		Parser_free(xmlParser);
		return rc;
	}

	xmlParser->curPtr = xmlParser->dataBuffer;
	rc = Parser_parseDocument(retDoc, xmlParser);
	return rc;
}


void ixml_membuf_init(ixml_membuf *m)
{
	assert(m != NULL);

	m->size_inc = MEMBUF_DEF_SIZE_INC;
	m->buf = NULL;
	m->length = (size_t)0;
	m->capacity = (size_t)0;
}


int ixmlDocument_createDocumentEx(IXML_Document **rtDoc)
{
	IXML_Document *doc;
	int errCode = IXML_SUCCESS;

	doc = NULL;
	doc = (IXML_Document *)malloc(sizeof(IXML_Document));
	if (doc == NULL) {
		errCode = IXML_INSUFFICIENT_MEMORY;
		goto ErrorHandler;
	}

	ixmlDocument_init(doc);

	doc->n.nodeName = strdup((const char *)DOCUMENTNODENAME);
	if (doc->n.nodeName == NULL) {
		ixmlDocument_free(doc);
		doc = NULL;
		errCode = IXML_INSUFFICIENT_MEMORY;
		goto ErrorHandler;
	}

	doc->n.nodeType = eDOCUMENT_NODE;
	doc->n.ownerDocument = doc;

ErrorHandler:
	*rtDoc = doc;
	return errCode;
}


void IxmlPrintf(const char *DbgFileName,
	int DbgLineNo,
	const char *FunctionName,
	const char *FmtStr,
	...)
{
	va_list ArgList;

	FILE *fp = stdout;
	fprintf(fp, "(%s::%s), line %d", DbgFileName, FunctionName, DbgLineNo);
	if (FmtStr) {
		fprintf(fp, ": ");
		va_start(ArgList, FmtStr);
		vfprintf(fp, FmtStr, ArgList);
		fflush(fp);
		va_end(ArgList);
	} else {
		fprintf(fp, "\n");
	}
}


void
p11_virtual_init (p11_virtual *virt,
                  CK_X_FUNCTION_LIST *funcs,
                  void *lower_module,
                  p11_destroyer lower_destroy)
{
	memcpy (virt, funcs, sizeof (CK_X_FUNCTION_LIST));
	virt->lower_module = lower_module;
	virt->lower_destroy = lower_destroy;
}


DLLEXPORT tjhandle tj3Init(int initType)
{
  static const char FUNCTION_NAME[] = "tj3Init";
  tjinstance *this = NULL;
  tjhandle retval = NULL;

  if (initType < 0 || initType >= TJ_NUMINIT)
    THROWG("Invalid argument", NULL);

  if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL)
    THROWG("Memory allocation failure", NULL);
  memset(this, 0, sizeof(tjinstance));
  SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");

  this->quality = -1;
  this->subsamp = TJSAMP_UNKNOWN;
  this->jpegWidth = -1;
  this->jpegHeight = -1;
  this->precision = 8;
  this->colorspace = -1;
  this->losslessPSV = 1;
  this->xDensity = 1;
  this->yDensity = 1;
  this->scalingFactor = TJUNSCALED;

  switch (initType) {
  case TJINIT_COMPRESS:  return _tjInitCompress(this);
  case TJINIT_DECOMPRESS:  return _tjInitDecompress(this);
  case TJINIT_TRANSFORM:
    retval = _tjInitCompress(this);
    if (!retval) return NULL;
    retval = _tjInitDecompress(this);
    return retval;
  }

bailout:
  return retval;
}


GLOBAL(struct jpeg_error_mgr *)
jpeg_std_error(struct jpeg_error_mgr *err)
{
  err->error_exit = error_exit;
  err->emit_message = emit_message;
  err->output_message = output_message;
  err->format_message = format_message;
  err->reset_error_mgr = reset_error_mgr;

  err->trace_level = 0;
  err->num_warnings = 0;
  err->msg_code = 0;

  err->jpeg_message_table = jpeg_std_message_table;
  err->last_jpeg_message = (int)JMSG_LASTMSGCODE - 1;

  err->addon_message_table = NULL;
  err->first_addon_message = 0;
  err->last_addon_message = 0;

  return err;
}


GLOBAL(void)
jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
{
  int i;

  cinfo->mem = NULL;
  if (version != JPEG_LIB_VERSION)
    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  if (structsize != sizeof(struct jpeg_compress_struct))
    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
             (int)sizeof(struct jpeg_compress_struct), (int)structsize);

  {
    struct jpeg_error_mgr *err = cinfo->err;
    void *client_data = cinfo->client_data;
    memset(cinfo, 0, sizeof(struct jpeg_compress_struct));
    cinfo->err = err;
    cinfo->client_data = client_data;
  }
  cinfo->is_decompressor = FALSE;

  jinit_memory_mgr((j_common_ptr)cinfo);

  cinfo->progress = NULL;
  cinfo->dest = NULL;

  cinfo->comp_info = NULL;

  for (i = 0; i < NUM_QUANT_TBLS; i++) {
    cinfo->quant_tbl_ptrs[i] = NULL;
#if JPEG_LIB_VERSION >= 70
    cinfo->q_scale_factor[i] = 100;
#endif
  }

  for (i = 0; i < NUM_HUFF_TBLS; i++) {
    cinfo->dc_huff_tbl_ptrs[i] = NULL;
    cinfo->ac_huff_tbl_ptrs[i] = NULL;
  }

#if JPEG_LIB_VERSION >= 80

  cinfo->block_size = DCTSIZE;
  cinfo->natural_order = jpeg_natural_order;
  cinfo->lim_Se = DCTSIZE2 - 1;
#endif

  cinfo->script_space = NULL;

  cinfo->input_gamma = 1.0;

  cinfo->data_precision = BITS_IN_JSAMPLE;

  cinfo->global_state = CSTATE_START;

  cinfo->master = (struct jpeg_comp_master *)
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
                                  sizeof(my_comp_master));
  memset(cinfo->master, 0, sizeof(my_comp_master));
}


GLOBAL(void)
jinit_memory_mgr(j_common_ptr cinfo)
{
  my_mem_ptr mem;
  long max_to_use;
  int pool;
  size_t test_mac;

  cinfo->mem = NULL;

  if ((ALIGN_SIZE & (ALIGN_SIZE - 1)) != 0)
    ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);

  test_mac = (size_t)MAX_ALLOC_CHUNK;
  if ((long)test_mac != MAX_ALLOC_CHUNK ||
      (MAX_ALLOC_CHUNK % ALIGN_SIZE) != 0)
    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);

  max_to_use = jpeg_mem_init(cinfo);

  mem = (my_mem_ptr)jpeg_get_small(cinfo, sizeof(my_memory_mgr));

  if (mem == NULL) {
    jpeg_mem_term(cinfo);
    ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  }

  mem->pub.alloc_small = alloc_small;
  mem->pub.alloc_large = alloc_large;
  mem->pub.alloc_sarray = alloc_sarray;
  mem->pub.alloc_barray = alloc_barray;
  mem->pub.request_virt_sarray = request_virt_sarray;
  mem->pub.request_virt_barray = request_virt_barray;
  mem->pub.realize_virt_arrays = realize_virt_arrays;
  mem->pub.access_virt_sarray = access_virt_sarray;
  mem->pub.access_virt_barray = access_virt_barray;
  mem->pub.free_pool = free_pool;
  mem->pub.self_destruct = self_destruct;

  mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;

  mem->pub.max_memory_to_use = max_to_use;

  for (pool = JPOOL_NUMPOOLS - 1; pool >= JPOOL_PERMANENT; pool--) {
    mem->small_list[pool] = NULL;
    mem->large_list[pool] = NULL;
  }
  mem->virt_sarray_list = NULL;
  mem->virt_barray_list = NULL;

  mem->total_space_allocated = sizeof(my_memory_mgr);

  cinfo->mem = &mem->pub;

#ifndef NO_GETENV
  {
    char memenv[30] = { 0 };

    if (!GETENV_S(memenv, 30, "JPEGMEM") && strlen(memenv) > 0) {
      char ch = 'x';

#ifdef _MSC_VER
      if (sscanf_s(memenv, "%ld%c", &max_to_use, &ch, 1) > 0) {
#else
      if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
#endif
        if (ch == 'm' || ch == 'M')
          max_to_use *= 1000L;
        mem->pub.max_memory_to_use = max_to_use * 1000L;
      }
    }
  }
#endif

}


GLOBAL(void)
jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer,
                 size_t *outsize, boolean alloc)
{
  boolean reused = FALSE;
  my_mem_dest_ptr dest;

  if (outbuffer == NULL || outsize == NULL)
    ERREXIT(cinfo, JERR_BUFFER_SIZE);

  if (cinfo->dest == NULL) {
    cinfo->dest = (struct jpeg_destination_mgr *)
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
                                  sizeof(my_mem_destination_mgr));
    dest = (my_mem_dest_ptr)cinfo->dest;
    dest->newbuffer = NULL;
    dest->buffer = NULL;
  } else if (cinfo->dest->init_destination != init_mem_destination) {

    ERREXIT(cinfo, JERR_BUFFER_SIZE);
  }

  dest = (my_mem_dest_ptr)cinfo->dest;
  dest->pub.init_destination = init_mem_destination;
  dest->pub.empty_output_buffer = empty_mem_output_buffer;
  dest->pub.term_destination = term_mem_destination;
  if (dest->buffer == *outbuffer && *outbuffer != NULL && alloc)
    reused = TRUE;
  dest->outbuffer = outbuffer;
  dest->outsize = outsize;
  dest->alloc = alloc;

  if (*outbuffer == NULL || *outsize == 0) {
    if (alloc) {

      dest->newbuffer = *outbuffer = (unsigned char *)malloc(OUTPUT_BUF_SIZE);
      if (dest->newbuffer == NULL)
        ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
      *outsize = OUTPUT_BUF_SIZE;
    } else
      ERREXIT(cinfo, JERR_BUFFER_SIZE);
  }

  dest->pub.next_output_byte = dest->buffer = *outbuffer;
  if (!reused)
    dest->bufsize = *outsize;
  dest->pub.free_in_buffer = dest->bufsize;
}


GLOBAL(void)
jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
{
  int i;

  cinfo->mem = NULL;
  if (version != JPEG_LIB_VERSION)
    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  if (structsize != sizeof(struct jpeg_compress_struct))
    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
             (int)sizeof(struct jpeg_compress_struct), (int)structsize);

  {
    struct jpeg_error_mgr *err = cinfo->err;
    void *client_data = cinfo->client_data;
    memset(cinfo, 0, sizeof(struct jpeg_compress_struct));
    cinfo->err = err;
    cinfo->client_data = client_data;
  }
  cinfo->is_decompressor = FALSE;

  jinit_memory_mgr((j_common_ptr)cinfo);

  cinfo->progress = NULL;
  cinfo->dest = NULL;

  cinfo->comp_info = NULL;

  for (i = 0; i < NUM_QUANT_TBLS; i++) {
    cinfo->quant_tbl_ptrs[i] = NULL;
#if JPEG_LIB_VERSION >= 70
    cinfo->q_scale_factor[i] = 100;
#endif
  }

  for (i = 0; i < NUM_HUFF_TBLS; i++) {
    cinfo->dc_huff_tbl_ptrs[i] = NULL;
    cinfo->ac_huff_tbl_ptrs[i] = NULL;
  }

#if JPEG_LIB_VERSION >= 80

  cinfo->block_size = DCTSIZE;
  cinfo->natural_order = jpeg_natural_order;
  cinfo->lim_Se = DCTSIZE2 - 1;
#endif

  cinfo->script_space = NULL;

  cinfo->input_gamma = 1.0;

  cinfo->global_state = CSTATE_START;
}


GLOBAL(void)
jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer,
                 unsigned long *outsize, boolean alloc)
{
  boolean reused = FALSE;
  my_mem_dest_ptr dest;

  if (outbuffer == NULL || outsize == NULL)
    ERREXIT(cinfo, JERR_BUFFER_SIZE);

  if (cinfo->dest == NULL) {
    cinfo->dest = (struct jpeg_destination_mgr *)
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
                                  sizeof(my_mem_destination_mgr));
    dest = (my_mem_dest_ptr)cinfo->dest;
    dest->newbuffer = NULL;
    dest->buffer = NULL;
  } else if (cinfo->dest->init_destination != init_mem_destination) {

    ERREXIT(cinfo, JERR_BUFFER_SIZE);
  }

  dest = (my_mem_dest_ptr)cinfo->dest;
  dest->pub.init_destination = init_mem_destination;
  dest->pub.empty_output_buffer = empty_mem_output_buffer;
  dest->pub.term_destination = term_mem_destination;
  if (dest->buffer == *outbuffer && *outbuffer != NULL && alloc)
    reused = TRUE;
  dest->outbuffer = outbuffer;
  dest->outsize = outsize;
  dest->alloc = alloc;

  if (*outbuffer == NULL || *outsize == 0) {
    if (alloc) {

      dest->newbuffer = *outbuffer = (unsigned char *)malloc(OUTPUT_BUF_SIZE);
      if (dest->newbuffer == NULL)
        ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
      *outsize = OUTPUT_BUF_SIZE;
    } else
      ERREXIT(cinfo, JERR_BUFFER_SIZE);
  }

  dest->pub.next_output_byte = dest->buffer = *outbuffer;
  if (!reused)
    dest->bufsize = *outsize;
  dest->pub.free_in_buffer = dest->bufsize;
}


GLOBAL(void)
jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize)
{
  int i;

  cinfo->mem = NULL;
  if (version != JPEG_LIB_VERSION)
    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  if (structsize != sizeof(struct jpeg_decompress_struct))
    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
             (int)sizeof(struct jpeg_decompress_struct), (int)structsize);

  {
    struct jpeg_error_mgr *err = cinfo->err;
    void *client_data = cinfo->client_data;
    memset(cinfo, 0, sizeof(struct jpeg_decompress_struct));
    cinfo->err = err;
    cinfo->client_data = client_data;
  }
  cinfo->is_decompressor = TRUE;

  jinit_memory_mgr((j_common_ptr)cinfo);

  cinfo->progress = NULL;
  cinfo->src = NULL;

  for (i = 0; i < NUM_QUANT_TBLS; i++)
    cinfo->quant_tbl_ptrs[i] = NULL;

  for (i = 0; i < NUM_HUFF_TBLS; i++) {
    cinfo->dc_huff_tbl_ptrs[i] = NULL;
    cinfo->ac_huff_tbl_ptrs[i] = NULL;
  }

  cinfo->marker_list = NULL;
  jinit_marker_reader(cinfo);

  jinit_input_controller(cinfo);

  cinfo->global_state = DSTATE_START;

  cinfo->master = (struct jpeg_decomp_master *)
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
                                sizeof(my_decomp_master));
  memset(cinfo->master, 0, sizeof(my_decomp_master));
}


GLOBAL(void)
jinit_marker_reader(j_decompress_ptr cinfo)
{
  my_marker_ptr marker;
  int i;

  marker = (my_marker_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
                                sizeof(my_marker_reader));
  cinfo->marker = (struct jpeg_marker_reader *)marker;

  marker->pub.reset_marker_reader = reset_marker_reader;
  marker->pub.read_markers = read_markers;
  marker->pub.read_restart_marker = read_restart_marker;

  marker->process_COM = skip_variable;
  marker->length_limit_COM = 0;
  for (i = 0; i < 16; i++) {
    marker->process_APPn[i] = skip_variable;
    marker->length_limit_APPn[i] = 0;
  }
  marker->process_APPn[0] = get_interesting_appn;
  marker->process_APPn[14] = get_interesting_appn;

  reset_marker_reader(cinfo);
}


GLOBAL(void)
jinit_input_controller(j_decompress_ptr cinfo)
{
  my_inputctl_ptr inputctl;

  inputctl = (my_inputctl_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
                                sizeof(my_input_controller));
  cinfo->inputctl = (struct jpeg_input_controller *)inputctl;

  inputctl->pub.consume_input = consume_markers;
  inputctl->pub.reset_input_controller = reset_input_controller;
  inputctl->pub.start_input_pass = start_input_pass;
  inputctl->pub.finish_input_pass = finish_input_pass;

  inputctl->pub.has_multiple_scans = FALSE;
  inputctl->pub.eoi_reached = FALSE;
  inputctl->inheaders = TRUE;
}


GLOBAL(void)
jpeg_mem_src_tj(j_decompress_ptr cinfo, const unsigned char *inbuffer,
                unsigned long insize)
{
  struct jpeg_source_mgr *src;

  if (inbuffer == NULL || insize == 0)
    ERREXIT(cinfo, JERR_INPUT_EMPTY);

  if (cinfo->src == NULL) {
    cinfo->src = (struct jpeg_source_mgr *)
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
                                  sizeof(struct jpeg_source_mgr));
  } else if (cinfo->src->init_source != init_mem_source) {

    ERREXIT(cinfo, JERR_BUFFER_SIZE);
  }

  src = cinfo->src;
  src->init_source = init_mem_source;
  src->fill_input_buffer = fill_mem_input_buffer;
  src->skip_input_data = skip_input_data;
  src->resync_to_restart = jpeg_resync_to_restart;
  src->term_source = term_source;
  src->bytes_in_buffer = (size_t)insize;
  src->next_input_byte = (const JOCTET *)inbuffer;
}


GLOBAL(void)
jpeg_CreateDecompress(j_decompress_ptr cinfo, int version, size_t structsize)
{
  int i;

  cinfo->mem = NULL;
  if (version != JPEG_LIB_VERSION)
    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  if (structsize != sizeof(struct jpeg_decompress_struct))
    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
             (int)sizeof(struct jpeg_decompress_struct), (int)structsize);

  {
    struct jpeg_error_mgr *err = cinfo->err;
    void *client_data = cinfo->client_data;
    memset(cinfo, 0, sizeof(struct jpeg_decompress_struct));
    cinfo->err = err;
    cinfo->client_data = client_data;
  }
  cinfo->is_decompressor = TRUE;

  jinit_memory_mgr((j_common_ptr)cinfo);

  cinfo->progress = NULL;
  cinfo->src = NULL;

  for (i = 0; i < NUM_QUANT_TBLS; i++)
    cinfo->quant_tbl_ptrs[i] = NULL;

  for (i = 0; i < NUM_HUFF_TBLS; i++) {
    cinfo->dc_huff_tbl_ptrs[i] = NULL;
    cinfo->ac_huff_tbl_ptrs[i] = NULL;
  }

  cinfo->marker_list = NULL;
  jinit_marker_reader(cinfo);

  jinit_input_controller(cinfo);

  cinfo->data_precision = BITS_IN_JSAMPLE;

  cinfo->global_state = DSTATE_START;

  cinfo->master = (struct jpeg_decomp_master *)
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
                                sizeof(my_decomp_master));
  memset(cinfo->master, 0, sizeof(my_decomp_master));
}


GLOBAL(void)
jpeg_mem_src_tj(j_decompress_ptr cinfo, const unsigned char *inbuffer,
                size_t insize)
{
  struct jpeg_source_mgr *src;

  if (inbuffer == NULL || insize == 0)
    ERREXIT(cinfo, JERR_INPUT_EMPTY);

  if (cinfo->src == NULL) {
    cinfo->src = (struct jpeg_source_mgr *)
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
                                  sizeof(struct jpeg_source_mgr));
  } else if (cinfo->src->init_source != init_mem_source) {

    ERREXIT(cinfo, JERR_BUFFER_SIZE);
  }

  src = cinfo->src;
  src->init_source = init_mem_source;
  src->fill_input_buffer = fill_mem_input_buffer;
  src->skip_input_data = skip_input_data;
  src->resync_to_restart = jpeg_resync_to_restart;
  src->term_source = term_source;
  src->bytes_in_buffer = insize;
  src->next_input_byte = (const JOCTET *)inbuffer;
}


GLOBAL(cjpeg_source_ptr)
jinit_read_targa(j_compress_ptr cinfo)
{
  tga_source_ptr source;

  source = (tga_source_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
                                sizeof(tga_source_struct));
  source->cinfo = cinfo;

  source->pub.start_input = start_input_tga;
  source->pub.finish_input = finish_input_tga;
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  source->pub.max_pixels = 0;
#endif

  return (cjpeg_source_ptr)source;
}


GLOBAL(cjpeg_source_ptr)
jinit_read_gif(j_compress_ptr cinfo)
{
  gif_source_ptr source;

  source = (gif_source_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
                                sizeof(gif_source_struct));
  source->cinfo = cinfo;

  source->pub.start_input = start_input_gif;
  source->pub.finish_input = finish_input_gif;
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  source->pub.max_pixels = 0;
#endif

  return (cjpeg_source_ptr)source;
}


GLOBAL(cjpeg_source_ptr)
jinit_read_bmp(j_compress_ptr cinfo, boolean use_inversion_array)
{
  bmp_source_ptr source;

  source = (bmp_source_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
                                sizeof(bmp_source_struct));
  source->cinfo = cinfo;

  source->pub.start_input = start_input_bmp;
  source->pub.finish_input = finish_input_bmp;
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  source->pub.max_pixels = 0;
#endif

  source->use_inversion_array = use_inversion_array;

  return (cjpeg_source_ptr)source;
}


GLOBAL(cjpeg_source_ptr)
jinit_read_ppm(j_compress_ptr cinfo)
{
  ppm_source_ptr source;

  source = (ppm_source_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
                                sizeof(ppm_source_struct));

  source->pub.start_input = start_input_ppm;
  source->pub.finish_input = finish_input_ppm;
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  source->pub.max_pixels = 0;
#endif

  return (cjpeg_source_ptr)source;
}


int device_alloc(struct crypt_device *cd, struct device **device, const char *path)
{
	struct device *dev;
	int r;

	r = device_alloc_no_check(&dev, path);
	if (r < 0)
		return r;

	if (dev) {
		r = device_ready(cd, dev);
		if (!r) {
			dev->init_done = 1;
		} else if (r == -ENOTBLK) {

		} else if (r < 0) {
			free(dev->path);
			free(dev);
			return -ENOTBLK;
		}
	}

	*device = dev;
	return 0;
}


void    msg_vstream_init(const char *name, VSTREAM *vp)
{
    static int first_call = 1;

    msg_tag = name;
    msg_stream = vp;
    if (first_call) {
	first_call = 0;
	msg_output(msg_vstream_print);
    }
}


ssize_t is_header_buf(const char *str, ssize_t str_len)
{
    const unsigned char *cp;
    int     state;
    int     c;
    ssize_t len;

#define INIT		0
#define IN_CHAR		1
#define IN_CHAR_SPACE	2
#define CU_CHAR_PTR(x)	((const unsigned char *) (x))

    for (len = 0, state = INIT, cp = CU_CHAR_PTR(str); ; cp++) {
	if (str_len != IS_HEADER_NULL_TERMINATED && str_len-- <= 0)
	    return (0);
	switch (c = *cp) {
	default:
	    if (c == 0 || !ISASCII(c) || ISCNTRL(c))
		return (0);
	    if (state == INIT)
		state = IN_CHAR;
	    if (state == IN_CHAR) {
		len++;
		continue;
	    }
	    return (0);
	case ' ':
	case '\t':
	    if (state == IN_CHAR)
		state = IN_CHAR_SPACE;
	    if (state == IN_CHAR_SPACE)
		continue;
	    return (0);
	case ':':
	    return ((state == IN_CHAR || state == IN_CHAR_SPACE) ? len : 0);
	}
    }

    return (0);
}


void    msg_output(MSG_OUTPUT_FN output_fn)
{
    int     i;

    if (msg_buffers[MSG_OUT_NESTING_LIMIT - 1] == 0) {
	for (i = 0; i < MSG_OUT_NESTING_LIMIT; i++)
	    msg_buffers[i] = vstring_alloc(100);
    }

    if (msg_output_fn_count == 0)
	msg_output_fn = (MSG_OUTPUT_FN *) mymalloc(sizeof(*msg_output_fn));
    else
	msg_output_fn = (MSG_OUTPUT_FN *) myrealloc((void *) msg_output_fn,
			(msg_output_fn_count + 1) * sizeof(*msg_output_fn));
    msg_output_fn[msg_output_fn_count++] = output_fn;
}


ssh_key pki_private_key_from_base64(const char *b64_key,
                                    const char *passphrase,
                                    ssh_auth_callback auth_fn,
                                    void *auth_data)
{
    BIO *mem = NULL;
#if OPENSSL_VERSION_NUMBER < 0x30000000L
    EC_KEY *ecdsa = NULL;
#endif
    uint8_t *ed25519 = NULL;
    uint8_t *ed25519_pubkey = NULL;
    ssh_key key = NULL;
    enum ssh_keytypes_e type = SSH_KEYTYPE_UNKNOWN;
    EVP_PKEY *pkey = NULL;

    mem = BIO_new_mem_buf((void*)b64_key, -1);

    if (passphrase == NULL) {
        if (auth_fn) {
            struct pem_get_password_struct pgp = { auth_fn, auth_data };

            pkey = PEM_read_bio_PrivateKey(mem, NULL, pem_get_password, &pgp);
        } else {

            pkey = PEM_read_bio_PrivateKey(mem, NULL, NULL, NULL);
        }
    } else {
        pkey = PEM_read_bio_PrivateKey(mem, NULL, NULL, (void *) passphrase);
    }

    BIO_free(mem);

    if (pkey == NULL) {
        SSH_LOG(SSH_LOG_TRACE,
                "Error parsing private key: %s",
                ERR_error_string(ERR_get_error(), NULL));
        return NULL;
    }
    switch (EVP_PKEY_base_id(pkey)) {
    case EVP_PKEY_RSA:
        type = SSH_KEYTYPE_RSA;
        break;
    case EVP_PKEY_EC:
#ifdef HAVE_OPENSSL_ECC
#if OPENSSL_VERSION_NUMBER < 0x30000000L
        ecdsa = EVP_PKEY_get0_EC_KEY(pkey);
        if (ecdsa == NULL) {
            SSH_LOG(SSH_LOG_TRACE,
		    "Error parsing private key: %s",
                    ERR_error_string(ERR_get_error(), NULL));
            goto fail;
        }
#endif

#if OPENSSL_VERSION_NUMBER < 0x30000000L
        type = pki_key_ecdsa_to_key_type(ecdsa);
#else
        type = pki_key_ecdsa_to_key_type(pkey);
#endif
        if (type == SSH_KEYTYPE_UNKNOWN) {
            SSH_LOG(SSH_LOG_TRACE, "Invalid private key.");
            goto fail;
        }

        break;
#endif
    case EVP_PKEY_ED25519:
    {
        size_t key_len;
        int evp_rc = 0;

        evp_rc = EVP_PKEY_get_raw_private_key(pkey, NULL, &key_len);
        if (evp_rc != 1) {
            SSH_LOG(SSH_LOG_TRACE,
                    "Failed to get ed25519 raw private key length:  %s",
                    ERR_error_string(ERR_get_error(), NULL));
            goto fail;
        }

        if (key_len != ED25519_KEY_LEN) {
            goto fail;
        }

        ed25519 = malloc(key_len);
        if (ed25519 == NULL) {
            SSH_LOG(SSH_LOG_TRACE, "Out of memory");
            goto fail;
        }

        evp_rc = EVP_PKEY_get_raw_private_key(pkey, (uint8_t *)ed25519,
                                              &key_len);
        if (evp_rc != 1) {
            SSH_LOG(SSH_LOG_TRACE,
                    "Failed to get ed25519 raw private key:  %s",
                    ERR_error_string(ERR_get_error(), NULL));
            goto fail;
        }

        ed25519_pubkey = malloc(ED25519_KEY_LEN);
        if (ed25519_pubkey == NULL) {
            SSH_LOG(SSH_LOG_TRACE, "Out of memory");
            goto fail;
        }

        evp_rc = EVP_PKEY_get_raw_public_key(pkey, (uint8_t *)ed25519_pubkey,
                                             &key_len);
        if (evp_rc != 1) {
            SSH_LOG(SSH_LOG_TRACE,
                    "Failed to get ed25519 raw public key:  %s",
                    ERR_error_string(ERR_get_error(), NULL));
            goto fail;
        }
        type = SSH_KEYTYPE_ED25519;

    }
    break;
    default:
        SSH_LOG(SSH_LOG_TRACE, "Unknown or invalid private key type %d",
                EVP_PKEY_base_id(pkey));
        EVP_PKEY_free(pkey);
        return NULL;
    }

    key = ssh_key_new();
    if (key == NULL) {
        goto fail;
    }

    key->type = type;
    key->type_c = ssh_key_type_to_char(type);
    key->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
    key->key = pkey;
    key->ed25519_privkey = ed25519;
    key->ed25519_pubkey = ed25519_pubkey;
#ifdef HAVE_OPENSSL_ECC
    if (is_ecdsa_key_type(key->type)) {
#if OPENSSL_VERSION_NUMBER < 0x30000000L
        key->ecdsa_nid = pki_key_ecdsa_to_nid(ecdsa);
#else
        key->ecdsa_nid = pki_key_ecdsa_to_nid(key->key);
#endif
    }
#endif

    return key;
fail:
    EVP_PKEY_free(pkey);
    ssh_key_free(key);
    SAFE_FREE(ed25519);
    SAFE_FREE(ed25519_pubkey);
    return NULL;
}


ssh_bind ssh_bind_new(void) {
    ssh_bind ptr;

    ptr = calloc(1, sizeof(struct ssh_bind_struct));
    if (ptr == NULL) {
        return NULL;
    }
    ptr->bindfd = SSH_INVALID_SOCKET;
    ptr->bindport = 22;
    ptr->common.log_verbosity = 0;

    return ptr;
}


ssh_session ssh_new(void)
{
    ssh_session session;
    char *id = NULL;
    int rc;

    session = calloc(1, sizeof (struct ssh_session_struct));
    if (session == NULL) {
        return NULL;
    }

    session->next_crypto = crypto_new();
    if (session->next_crypto == NULL) {
        goto err;
    }

    session->socket = ssh_socket_new(session);
    if (session->socket == NULL) {
        goto err;
    }

    session->out_buffer = ssh_buffer_new();
    if (session->out_buffer == NULL) {
        goto err;
    }

    session->in_buffer = ssh_buffer_new();
    if (session->in_buffer == NULL) {
        goto err;
    }

    session->out_queue = ssh_list_new();
    if (session->out_queue == NULL) {
        goto err;
    }

    session->alive = 0;
    session->auth.supported_methods = 0;
    ssh_set_blocking(session, 1);
    session->maxchannel = FIRST_CHANNEL;

    session->agent = ssh_agent_new(session);
    if (session->agent == NULL) {
        goto err;
    }

    session->opts.StrictHostKeyChecking = 1;
    session->opts.port = 22;
    session->opts.fd = -1;
    session->opts.compressionlevel = 7;
    session->opts.nodelay = 0;
    session->opts.identities_only = false;
    session->opts.control_master = SSH_CONTROL_MASTER_NO;

    session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
                          SSH_OPT_FLAG_PUBKEY_AUTH |
                          SSH_OPT_FLAG_KBDINT_AUTH |
                          SSH_OPT_FLAG_GSSAPI_AUTH;

    session->opts.exp_flags = 0;

    session->opts.identity = ssh_list_new();
    if (session->opts.identity == NULL) {
        goto err;
    }
    session->opts.identity_non_exp = ssh_list_new();
    if (session->opts.identity_non_exp == NULL) {
        goto err;
    }

    session->opts.certificate = ssh_list_new();
    if (session->opts.certificate == NULL) {
        goto err;
    }
    session->opts.certificate_non_exp = ssh_list_new();
    if (session->opts.certificate_non_exp == NULL) {
        goto err;
    }

    id = strdup("%d/id_ed25519");
    if (id == NULL) {
        goto err;
    }

    rc = ssh_list_append(session->opts.identity_non_exp, id);
    if (rc == SSH_ERROR) {
        goto err;
    }

#ifdef HAVE_ECC
    id = strdup("%d/id_ecdsa");
    if (id == NULL) {
        goto err;
    }
    rc = ssh_list_append(session->opts.identity_non_exp, id);
    if (rc == SSH_ERROR) {
        goto err;
    }
#endif

    id = strdup("%d/id_rsa");
    if (id == NULL) {
        goto err;
    }
    rc = ssh_list_append(session->opts.identity_non_exp, id);
    if (rc == SSH_ERROR) {
        goto err;
    }

    session->session_state = SSH_SESSION_STATE_NONE;
    session->pending_call_state = SSH_PENDING_CALL_NONE;
    session->packet_state = PACKET_STATE_INIT;
    session->dh_handshake_state = DH_STATE_INIT;
    session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;

    session->auth.state = SSH_AUTH_STATE_NONE;
    session->auth.service_state = SSH_AUTH_SERVICE_NONE;

    return session;

err:
    free(id);
    ssh_free(session);
    return NULL;
}


ssh_socket ssh_socket_new(ssh_session session)
{
    ssh_socket s;

    s = calloc(1, sizeof(struct ssh_socket_struct));
    if (s == NULL) {
        ssh_set_error_oom(session);
        return NULL;
    }
    s->fd = SSH_INVALID_SOCKET;
    s->last_errno = -1;
    s->fd_is_socket = 1;
    s->session = session;
    s->in_buffer = ssh_buffer_new();
    if (s->in_buffer == NULL) {
        ssh_set_error_oom(session);
        SAFE_FREE(s);
        return NULL;
    }
    s->out_buffer=ssh_buffer_new();
    if (s->out_buffer == NULL) {
        ssh_set_error_oom(session);
        SSH_BUFFER_FREE(s->in_buffer);
        SAFE_FREE(s);
        return NULL;
    }
    s->read_wontblock = 0;
    s->write_wontblock = 0;
    s->data_except = 0;
    s->poll_handle = NULL;
    s->state=SSH_SOCKET_NONE;
    return s;
}


ssh_poll_handle
ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb, void *userdata)
{
    ssh_poll_handle p;

    p = malloc(sizeof(struct ssh_poll_handle_struct));
    if (p == NULL) {
        return NULL;
    }
    ZERO_STRUCTP(p);

    p->x.fd = fd;
    p->events = events;
    p->cb = cb;
    p->cb_data = userdata;

    return p;
}


int ssh_send_banner(ssh_session session, int server)
{
    const char *banner = CLIENT_BANNER_SSH2;
    const char *terminator = "\r\n";

    char buffer[256] = {0};
    size_t len;
    int rc = SSH_ERROR;

    if (server == 1) {
        if (session->opts.custombanner == NULL){
            session->serverbanner = strdup(banner);
            if (session->serverbanner == NULL) {
                goto end;
            }
        } else {
            len = strlen(session->opts.custombanner);
            session->serverbanner = malloc(len + 8 + 1);
            if(session->serverbanner == NULL) {
                goto end;
            }
            snprintf(session->serverbanner,
                     len + 8 + 1,
                     "SSH-2.0-%s",
                     session->opts.custombanner);
        }

        snprintf(buffer,
                 sizeof(buffer),
                 "%s%s",
                 session->serverbanner,
                 terminator);
    } else {
        session->clientbanner = strdup(banner);
        if (session->clientbanner == NULL) {
            goto end;
        }

        snprintf(buffer,
                 sizeof(buffer),
                 "%s%s",
                 session->clientbanner,
                 terminator);
    }

    rc = ssh_socket_write(session->socket, buffer, strlen(buffer));
    if (rc == SSH_ERROR) {
        goto end;
    }
#ifdef WITH_PCAP
    if (session->pcap_ctx != NULL) {
        ssh_pcap_context_write(session->pcap_ctx,
                               SSH_PCAP_DIR_OUT,
                               buffer,
                               strlen(buffer),
                               strlen(buffer));
    }
#endif

    rc = SSH_OK;
end:
    return rc;
}


void _ssh_set_error(void *error,
                    int code,
                    const char *function,
                    const char *descr, ...)
{
    struct ssh_common_struct *err = error;
    va_list va;

    va_start(va, descr);
    vsnprintf(err->error.error_buffer, ERROR_BUFFERLEN, descr, va);
    va_end(va);

    err->error.error_code = code;
    if (ssh_get_log_level() == SSH_LOG_TRACE) {
        ssh_log_function(SSH_LOG_TRACE,
                         function,
                         err->error.error_buffer);
    }
}

0x733100 "Socket exception callback: %d (%d)"


void ssh_packet_register_socket_callback(ssh_session session, ssh_socket s)
{
    struct ssh_socket_callbacks_struct *callbacks = &session->socket_callbacks;

    callbacks->data = ssh_packet_socket_callback;
    callbacks->connected = NULL;
    callbacks->controlflow = ssh_packet_socket_controlflow_callback;
    callbacks->userdata = session;
    ssh_socket_set_callbacks(s, callbacks);
}


int ssh_config_parse_string(ssh_session session, const char *input)
{
    char line[MAX_LINE_SIZE] = {0};
    const char *c = input, *line_start = input;
    unsigned int line_num = 0, line_len;
    int parsing, rv;

    SSH_LOG(SSH_LOG_DEBUG, "Reading configuration data from string:");
    SSH_LOG(SSH_LOG_DEBUG, "START\n%s\nEND", input);

    parsing = 1;
    while (1) {
        line_num++;
        line_start = c;
        c = strchr(line_start, '\n');
        if (c == NULL) {

            c = strchr(line_start, '\0');
        }
        if (c == NULL) {

            SSH_LOG(SSH_LOG_TRACE, "No trailing '\\0' in config string");
            return SSH_ERROR;
        }
        line_len = c - line_start;
        if (line_len > MAX_LINE_SIZE - 1) {
            SSH_LOG(SSH_LOG_TRACE, "Line %u too long: %u characters",
                    line_num, line_len);
            return SSH_ERROR;
        }
        memcpy(line, line_start, line_len);
        line[line_len] = '\0';
        SSH_LOG(SSH_LOG_DEBUG, "Line %u: %s", line_num, line);
        rv = ssh_config_parse_line(session, line, line_num, &parsing, 0, false);
        if (rv < 0) {
            return SSH_ERROR;
        }
        if (*c == '\0') {
            break;
        }
        c++;
    }

    return SSH_OK;
}

Input: 0x12548a0 ""


int ssh_bind_config_parse_string(ssh_bind bind, const char *input)
{
    char line[MAX_LINE_SIZE] = {0};
    const char *c = input, *line_start = input;
    unsigned int line_num = 0, line_len;
    uint32_t parser_flags;
    int rv;

    uint8_t seen[BIND_CFG_MAX] = {0};

    SSH_LOG(SSH_LOG_DEBUG, "Reading bind configuration data from string:");
    SSH_LOG(SSH_LOG_DEBUG, "START\n%s\nEND", input);

    parser_flags = PARSING;
    while (1) {
        line_num++;
        line_start = c;
        c = strchr(line_start, '\n');
        if (c == NULL) {

            c = strchr(line_start, '\0');
        }
        if (c == NULL) {

            SSH_LOG(SSH_LOG_WARN, "No trailing '\\0' in config string");
            return SSH_ERROR;
        }
        line_len = c - line_start;
        if (line_len > MAX_LINE_SIZE - 1) {
            SSH_LOG(SSH_LOG_WARN, "Line %u too long: %u characters",
                    line_num, line_len);
            return SSH_ERROR;
        }
        memcpy(line, line_start, line_len);
        line[line_len] = '\0';
        SSH_LOG(SSH_LOG_DEBUG, "Line %u: %s", line_num, line);
        rv = ssh_bind_config_parse_line(bind, line, line_num, &parser_flags, seen, 0);
        if (rv < 0) {
            return SSH_ERROR;
        }
        if (*c == '\0') {
            break;
        }
        c++;
    }

    return SSH_OK;
}

Input: 0x12578a0 ""


krb5_error_code
ndr_dec_delegation_info(krb5_data *data, struct pac_s4u_delegation_info **out)
{
    krb5_error_code ret;
    struct pac_s4u_delegation_info *di = NULL;
    struct k5input in;
    uint32_t i, object_buffer_length, nservices;
    uint8_t version, endianness, common_header_length;

    *out = NULL;

    di = k5alloc(sizeof(*di), &ret);
    if (di == NULL)
        return ret;

    k5_input_init(&in, data->data, data->length);

    version = k5_input_get_byte(&in);
    endianness = k5_input_get_byte(&in);
    common_header_length = k5_input_get_uint16_le(&in);
    (void)k5_input_get_uint32_le(&in);
    if (version != 1 || endianness != 0x10 || common_header_length != 8) {
        ret = EINVAL;
        goto error;
    }

    object_buffer_length = k5_input_get_uint32_le(&in);
    if (data->length < 16 || object_buffer_length != data->length - 16) {
        ret = EINVAL;
        goto error;
    }

    (void)k5_input_get_uint32_le(&in);

    (void)k5_input_get_uint32_le(&in);

    (void)k5_input_get_uint16_le(&in);

    (void)k5_input_get_uint16_le(&in);

    (void)k5_input_get_uint32_le(&in);

    (void)k5_input_get_uint32_le(&in);

    (void)k5_input_get_uint32_le(&in);

    ret = dec_wchar_pointer(&in, &di->proxy_target);
    if (ret)
        goto error;
    nservices = k5_input_get_uint32_le(&in);

    if (nservices > data->length / 8) {
        ret = ERANGE;
        goto error;
    }
    (void)k5_input_get_bytes(&in, 8 * nservices);

    di->transited_services = k5calloc(nservices + 1, sizeof(char *), &ret);
    if (di->transited_services == NULL)
        goto error;

    for (i = 0; i < nservices; i++) {
        ret = dec_wchar_pointer(&in, &di->transited_services[i]);
        if (ret)
            goto error;
        di->transited_services_length++;
    }

    ret = in.status;
    if (ret)
        goto error;

    *out = di;
    return 0;

error:
    ndr_free_delegation_info(di);
    return ret;
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x1332bcc00081001


void
k5_buf_init_dynamic(struct k5buf *buf)
{
    buf->buftype = K5BUF_DYNAMIC;
    buf->space = 128;
    buf->data = malloc(buf->space);
    if (buf->data == NULL) {
        set_error(buf);
        return;
    }
    buf->len = 0;
}

Traceback (most recent call last):
  File "/tracer/var_utils.py", line 72, in serialize_value_to_json
    if str(value) == "0x0":
gdb.MemoryError: Cannot access memory at address 0x65cc6ead


OM_uint32
gssint_get_mech_type(gss_OID OID, gss_buffer_t token)
{

    if (token->length >= sizeof(NTLMSSP_SIGNATURE) &&
	memcmp(token->value, NTLMSSP_SIGNATURE,
	       sizeof(NTLMSSP_SIGNATURE)) == 0) {
	*OID = gss_ntlm_mechanism_oid_desc;
    } else if (token->length != 0 &&
	       ((char *)token->value)[0] == 0x6E) {

	*OID = gss_krb5_mechanism_oid_desc;
    } else if (token->length == 0) {
	*OID = gss_spnego_mechanism_oid_desc;
    } else {
	return gssint_get_mech_type_oid(OID, token);
    }

    return (GSS_S_COMPLETE);
}