Skip to content

Commit

Permalink
Applied updates
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Sep 13, 2023
1 parent 8f6f2ee commit 41a13a0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 12 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ([2.71])

AC_INIT(
[libfvde],
[20230729],
[20230913],
[[email protected]])

AC_CONFIG_SRCDIR(
Expand Down
14 changes: 12 additions & 2 deletions pyfvde/pyfvde.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ PyObject *pyfvde_get_version(
PyObject *self PYFVDE_ATTRIBUTE_UNUSED,
PyObject *arguments PYFVDE_ATTRIBUTE_UNUSED )
{
const char *errors = NULL;
const char *version_string = NULL;
size_t version_string_length = 0;

Expand All @@ -123,7 +122,7 @@ PyObject *pyfvde_get_version(
return( PyUnicode_DecodeUTF8(
version_string,
(Py_ssize_t) version_string_length,
errors ) );
NULL ) );
}

/* Checks if a volume has a FileVault Drive Encryption (FVDE) volume signature
Expand Down Expand Up @@ -183,15 +182,26 @@ PyObject *pyfvde_check_volume_signature(
PyErr_Clear();

#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
filename_wide = (wchar_t *) PyUnicode_AsWideCharString(
string_object,
NULL );
#else
filename_wide = (wchar_t *) PyUnicode_AsUnicode(
string_object );
#endif
Py_BEGIN_ALLOW_THREADS

result = libfvde_check_volume_signature_wide(
filename_wide,
&error );

Py_END_ALLOW_THREADS

#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
PyMem_Free(
filename_wide );
#endif
#else
utf8_string_object = PyUnicode_AsUTF8String(
string_object );
Expand Down
2 changes: 1 addition & 1 deletion pyfvde/pyfvde_file_object_io_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ ssize_t pyfvde_file_object_read_buffer(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to data to buffer.",
"%s: unable to copy data to buffer.",
function );

goto on_error;
Expand Down
3 changes: 1 addition & 2 deletions pyfvde/pyfvde_guid.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ PyObject *pyfvde_string_new_from_guid(
libcerror_error_t *error = NULL;
libfguid_identifier_t *guid = NULL;
PyObject *string_object = NULL;
const char *errors = NULL;
static char *function = "pyfvde_string_new_from_guid";

if( libfguid_identifier_initialize(
Expand Down Expand Up @@ -115,7 +114,7 @@ PyObject *pyfvde_string_new_from_guid(
string_object = PyUnicode_DecodeUTF8(
guid_string,
(Py_ssize_t) 36,
errors );
NULL );

return( string_object );

Expand Down
3 changes: 1 addition & 2 deletions pyfvde/pyfvde_logical_volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,6 @@ PyObject *pyfvde_logical_volume_get_name(
{
PyObject *string_object = NULL;
libcerror_error_t *error = NULL;
const char *errors = NULL;
static char *function = "pyfvde_logical_volume_get_name";
char *utf8_string = NULL;
size_t utf8_string_size = 0;
Expand Down Expand Up @@ -1186,7 +1185,7 @@ PyObject *pyfvde_logical_volume_get_name(
string_object = PyUnicode_DecodeUTF8(
utf8_string,
(Py_ssize_t) utf8_string_size - 1,
errors );
NULL );

if( string_object == NULL )
{
Expand Down
49 changes: 47 additions & 2 deletions pyfvde/pyfvde_volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,14 @@ PyObject *pyfvde_volume_open(
PyErr_Clear();

#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
filename_wide = (wchar_t *) PyUnicode_AsWideCharString(
string_object,
NULL );
#else
filename_wide = (wchar_t *) PyUnicode_AsUnicode(
string_object );
#endif
Py_BEGIN_ALLOW_THREADS

result = libfvde_volume_open_wide(
Expand All @@ -589,6 +595,11 @@ PyObject *pyfvde_volume_open(
&error );

Py_END_ALLOW_THREADS

#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
PyMem_Free(
filename_wide );
#endif
#else
utf8_string_object = PyUnicode_AsUTF8String(
string_object );
Expand Down Expand Up @@ -855,9 +866,11 @@ PyObject *pyfvde_volume_open_physical_volume_files(
PyObject *keywords )
{
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
wchar_t *filename_wide = NULL;
#endif
wchar_t **filenames = NULL;
wchar_t *filename = NULL;
const char *errors = NULL;
char *narrow_string = NULL;
size_t narrow_string_size = 0;
int is_unicode_string = 0;
Expand Down Expand Up @@ -1038,8 +1051,16 @@ PyObject *pyfvde_volume_open_physical_volume_files(
#if defined( HAVE_WIDE_SYSTEM_CHARACTER )
if( is_unicode_string != 0 )
{
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
filename_wide = (wchar_t *) PyUnicode_AsWideCharString(
string_object,
NULL );

filename = filename_wide;
#else
filename = (wchar_t *) PyUnicode_AsUnicode(
string_object );
#endif
}
else
{
Expand All @@ -1060,7 +1081,7 @@ PyObject *pyfvde_volume_open_physical_volume_files(
narrow_string,
narrow_string_size,
PyUnicode_GetDefaultEncoding(),
errors );
NULL );

if( filename_string_object == NULL )
{
Expand All @@ -1072,8 +1093,16 @@ PyObject *pyfvde_volume_open_physical_volume_files(

goto on_error;
}
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
filename_wide = (wchar_t *) PyUnicode_AsWideCharString(
filename_string_object,
NULL );

filename = filename_wide;
#else
filename = (wchar_t *) PyUnicode_AsUnicode(
filename_string_object );
#endif
}
filename_length = wide_string_length(
filename );
Expand Down Expand Up @@ -1130,6 +1159,15 @@ PyObject *pyfvde_volume_open_physical_volume_files(
}
( filenames[ filename_index ] )[ filename_length ] = 0;

#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
if( filename_wide != NULL )
{
PyMem_Free(
filename_wide );

filename_wide = NULL;
}
#endif
if( filename_string_object != NULL )
{
Py_DecRef(
Expand Down Expand Up @@ -1190,6 +1228,13 @@ PyObject *pyfvde_volume_open_physical_volume_files(
return( Py_None );

on_error:
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
if( filename_wide != NULL )
{
PyMem_Free(
filename_wide );
}
#endif
if( filename_string_object != NULL )
{
Py_DecRef(
Expand Down
3 changes: 1 addition & 2 deletions pyfvde/pyfvde_volume_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ PyObject *pyfvde_volume_group_get_name(
{
PyObject *string_object = NULL;
libcerror_error_t *error = NULL;
const char *errors = NULL;
static char *function = "pyfvde_volume_group_get_name";
char *utf8_string = NULL;
size_t utf8_string_size = 0;
Expand Down Expand Up @@ -537,7 +536,7 @@ PyObject *pyfvde_volume_group_get_name(
string_object = PyUnicode_DecodeUTF8(
utf8_string,
(Py_ssize_t) utf8_string_size - 1,
errors );
NULL );

if( string_object == NULL )
{
Expand Down

0 comments on commit 41a13a0

Please sign in to comment.