From 41a13a09d6d64157b84e6c30542751990ffaafaf Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Wed, 13 Sep 2023 06:52:47 +0200 Subject: [PATCH] Applied updates --- configure.ac | 2 +- pyfvde/pyfvde.c | 14 ++++++-- pyfvde/pyfvde_file_object_io_handle.c | 2 +- pyfvde/pyfvde_guid.c | 3 +- pyfvde/pyfvde_logical_volume.c | 3 +- pyfvde/pyfvde_volume.c | 49 +++++++++++++++++++++++++-- pyfvde/pyfvde_volume_group.c | 3 +- 7 files changed, 64 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 80ce6a4..6281b44 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ([2.71]) AC_INIT( [libfvde], - [20230729], + [20230913], [joachim.metz@gmail.com]) AC_CONFIG_SRCDIR( diff --git a/pyfvde/pyfvde.c b/pyfvde/pyfvde.c index e21b286..ca03095 100644 --- a/pyfvde/pyfvde.c +++ b/pyfvde/pyfvde.c @@ -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; @@ -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 @@ -183,8 +182,14 @@ 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( @@ -192,6 +197,11 @@ PyObject *pyfvde_check_volume_signature( &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 ); diff --git a/pyfvde/pyfvde_file_object_io_handle.c b/pyfvde/pyfvde_file_object_io_handle.c index 8845f20..a3632a4 100644 --- a/pyfvde/pyfvde_file_object_io_handle.c +++ b/pyfvde/pyfvde_file_object_io_handle.c @@ -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; diff --git a/pyfvde/pyfvde_guid.c b/pyfvde/pyfvde_guid.c index 374e2c3..786089b 100644 --- a/pyfvde/pyfvde_guid.c +++ b/pyfvde/pyfvde_guid.c @@ -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( @@ -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 ); diff --git a/pyfvde/pyfvde_logical_volume.c b/pyfvde/pyfvde_logical_volume.c index 5c6a896..eaf0569 100644 --- a/pyfvde/pyfvde_logical_volume.c +++ b/pyfvde/pyfvde_logical_volume.c @@ -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; @@ -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 ) { diff --git a/pyfvde/pyfvde_volume.c b/pyfvde/pyfvde_volume.c index 758829f..015ffe1 100644 --- a/pyfvde/pyfvde_volume.c +++ b/pyfvde/pyfvde_volume.c @@ -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( @@ -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 ); @@ -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; @@ -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 { @@ -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 ) { @@ -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 ); @@ -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( @@ -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( diff --git a/pyfvde/pyfvde_volume_group.c b/pyfvde/pyfvde_volume_group.c index fbf2924..22f79fb 100644 --- a/pyfvde/pyfvde_volume_group.c +++ b/pyfvde/pyfvde_volume_group.c @@ -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; @@ -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 ) {