Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions libpff/libpff_descriptors_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ int libpff_descriptors_index_initialize(
return( -1 );
}


/* Frees a descriptors index
* Returns 1 if successful or -1 on error
*/
Expand Down Expand Up @@ -345,13 +346,21 @@ int libpff_descriptors_index_get_index_value_by_identifier(

goto on_error;
}
lookup_index_value->data_identifier = lookup_index_value->data_identifier;
lookup_index_value->local_descriptors_identifier = lookup_index_value->local_descriptors_identifier;
lookup_index_value->parent_identifier = lookup_index_value->parent_identifier;
lookup_index_value->data_identifier = safe_index_value->data_identifier;
lookup_index_value->local_descriptors_identifier = safe_index_value->local_descriptors_identifier;
lookup_index_value->parent_identifier = safe_index_value->parent_identifier;

*index_value = lookup_index_value;

lookup_index_value = NULL;
}
}
if( lookup_index_value != NULL )
{
libpff_index_value_free(
&lookup_index_value,
NULL );
}
return( result );

on_error:
Expand Down Expand Up @@ -483,4 +492,3 @@ int libpff_descriptors_index_insert_recovered_index_value(
}
return( -1 );
}

16 changes: 12 additions & 4 deletions libpff/libpff_offsets_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ int libpff_offsets_index_initialize(
return( -1 );
}


/* Frees an offsets index
* Returns 1 if successful or -1 on error
*/
Expand Down Expand Up @@ -339,13 +340,21 @@ int libpff_offsets_index_get_index_value_by_identifier(

goto on_error;
}
lookup_index_value->file_offset = lookup_index_value->file_offset;
lookup_index_value->data_size = lookup_index_value->data_size;
lookup_index_value->reference_count = lookup_index_value->reference_count;
lookup_index_value->file_offset = safe_index_value->file_offset;
lookup_index_value->data_size = safe_index_value->data_size;
lookup_index_value->reference_count = safe_index_value->reference_count;

*index_value = lookup_index_value;

lookup_index_value = NULL;
}
}
if( lookup_index_value != NULL )
{
libpff_index_value_free(
&lookup_index_value,
NULL );
}
return( result );

on_error:
Expand Down Expand Up @@ -477,4 +486,3 @@ int libpff_offsets_index_insert_recovered_index_value(
}
return( -1 );
}

169 changes: 167 additions & 2 deletions tests/pff_test_descriptors_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "pff_test_unused.h"

#include "../libpff/libpff_descriptors_index.h"
#include "../libpff/libpff_index_value.h"
#include "../libpff/libpff_io_handle.h"

#if defined( __GNUC__ ) && !defined( LIBPFF_DLL_IMPORT )

Expand Down Expand Up @@ -75,6 +77,168 @@ int pff_test_descriptors_index_free(
return( 0 );
}

/* Tests recovered descriptor lookup field preservation.
* Returns 1 if successful or 0 if not.
*/
int pff_test_descriptors_index_get_index_value_by_identifier(
void )
{
libcerror_error_t *error = NULL;
libpff_descriptors_index_t *descriptors_index = NULL;
libpff_index_value_t *index_value = NULL;
libpff_index_value_t *recovered_value = NULL;
libpff_io_handle_t *io_handle = NULL;
int result = 0;

result = libpff_io_handle_initialize(
&io_handle,
&error );

PFF_TEST_ASSERT_EQUAL_INT(
"result",
result,
1 );

result = libpff_descriptors_index_initialize(
&descriptors_index,
0,
0,
&error );

PFF_TEST_ASSERT_EQUAL_INT(
"result",
result,
1 );

result = libpff_index_value_initialize(
&recovered_value,
&error );

PFF_TEST_ASSERT_EQUAL_INT(
"result",
result,
1 );

recovered_value->identifier = 0x1234;
recovered_value->data_identifier = 0x5678;
recovered_value->local_descriptors_identifier = 0x9abc;
recovered_value->parent_identifier = 0xdef0;

result = libpff_descriptors_index_insert_recovered_index_value(
descriptors_index,
recovered_value,
&error );

PFF_TEST_ASSERT_EQUAL_INT(
"result",
result,
1 );

recovered_value = NULL;

result = libpff_descriptors_index_get_index_value_by_identifier(
descriptors_index,
io_handle,
NULL,
0x1234,
1,
&index_value,
&error );

PFF_TEST_ASSERT_EQUAL_INT(
"result",
result,
1 );

PFF_TEST_ASSERT_IS_NOT_NULL(
"index_value",
index_value );

PFF_TEST_ASSERT_EQUAL_UINT64(
"index_value->data_identifier",
index_value->data_identifier,
(uint64_t) 0x5678 );

PFF_TEST_ASSERT_EQUAL_UINT64(
"index_value->local_descriptors_identifier",
index_value->local_descriptors_identifier,
(uint64_t) 0x9abc );

PFF_TEST_ASSERT_EQUAL_UINT32(
"index_value->parent_identifier",
index_value->parent_identifier,
(uint32_t) 0xdef0 );

PFF_TEST_ASSERT_IS_NULL(
"error",
error );

result = libpff_index_value_free(
&index_value,
&error );

PFF_TEST_ASSERT_EQUAL_INT(
"result",
result,
1 );

result = libpff_descriptors_index_free(
&descriptors_index,
&error );

PFF_TEST_ASSERT_EQUAL_INT(
"result",
result,
1 );

result = libpff_io_handle_free(
&io_handle,
&error );

PFF_TEST_ASSERT_EQUAL_INT(
"result",
result,
1 );

PFF_TEST_ASSERT_IS_NULL(
"error",
error );

return( 1 );

on_error:
if( error != NULL )
{
libcerror_error_free(
&error );
}
if( index_value != NULL )
{
libpff_index_value_free(
&index_value,
NULL );
}
if( recovered_value != NULL )
{
libpff_index_value_free(
&recovered_value,
NULL );
}
if( descriptors_index != NULL )
{
libpff_descriptors_index_free(
&descriptors_index,
NULL );
}
if( io_handle != NULL )
{
libpff_io_handle_free(
&io_handle,
NULL );
}
return( 0 );
}

#endif /* defined( __GNUC__ ) && !defined( LIBPFF_DLL_IMPORT ) */

/* The main program
Expand Down Expand Up @@ -102,7 +266,9 @@ int main(

/* TODO: add tests for libpff_descriptors_index_set_root_node */

/* TODO: add tests for libpff_descriptors_index_get_index_value_by_identifier */
PFF_TEST_RUN(
"libpff_descriptors_index_get_index_value_by_identifier",
pff_test_descriptors_index_get_index_value_by_identifier );

#endif /* defined( __GNUC__ ) && !defined( LIBPFF_DLL_IMPORT ) */

Expand All @@ -111,4 +277,3 @@ int main(
on_error:
return( EXIT_FAILURE );
}

Loading
Loading