diff --git a/0004-modify-error-value-for-Win32-file-handle.patch b/0004-modify-error-value-for-Win32-file-handle.patch new file mode 100644 index 0000000000000000000000000000000000000000..5ef0b43d4308fc51dd73e7b27d248093d94eaf56 --- /dev/null +++ b/0004-modify-error-value-for-Win32-file-handle.patch @@ -0,0 +1,148 @@ +From 3f8343ccdc1c02ee4969eac9a056fd1999544522 Mon Sep 17 00:00:00 2001 +From: ctl-ly +Date: Thu, 29 Dec 2022 14:48:22 +0800 +Subject: [PATCH] Use proper error value for Win32 file handle +The error value for Win32 file handle shoule be INVALID_HANDLE_VALUE, instead of NULL. Use proper error value for Win32 file handle + +--- + src/file_io.c | 37 ++++++++++++++----------------------- + 1 file changed, 14 insertions(+), 23 deletions(-) + +diff --git a/src/file_io.c b/src/file_io.c +index 9cd9379..9901e86 100644 +--- a/src/file_io.c ++++ b/src/file_io.c +@@ -620,7 +620,7 @@ psf_fopen (SF_PRIVATE *psf) + psf->error = 0 ; + psf->file.handle = psf_open_handle (&psf->file) ; + +- if (psf->file.handle == NULL) ++ if (psf->file.handle == INVALID_HANDLE_VALUE) + psf_log_syserr (psf, GetLastError ()) ; + + return psf->error ; +@@ -634,14 +634,14 @@ psf_fclose (SF_PRIVATE *psf) + return 0 ; + + if (psf->file.do_not_close_descriptor) +- { psf->file.handle = NULL ; ++ { psf->file.handle = INVALID_HANDLE_VALUE ; + return 0 ; + } ; + + if ((retval = psf_close_handle (psf->file.handle)) == -1) + psf_log_syserr (psf, GetLastError ()) ; + +- psf->file.handle = NULL ; ++ psf->file.handle = INVALID_HANDLE_VALUE ; + + return retval ; + } /* psf_fclose */ +@@ -649,13 +649,13 @@ psf_fclose (SF_PRIVATE *psf) + /* USE_WINDOWS_API */ int + psf_open_rsrc (SF_PRIVATE *psf) + { +- if (psf->rsrc.handle != NULL) ++ if (psf->rsrc.handle != INVALID_HANDLE_VALUE) + return 0 ; + + /* Test for MacOSX style resource fork on HPFS or HPFS+ filesystems. */ + snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s/rsrc", psf->file.path.c) ; + psf->error = SFE_NO_ERROR ; +- if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL) ++ if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != INVALID_HANDLE_VALUE) + { psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ; + return SFE_NO_ERROR ; + } ; +@@ -666,7 +666,7 @@ psf_open_rsrc (SF_PRIVATE *psf) + */ + snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s._%s", psf->file.dir.c, psf->file.name.c) ; + psf->error = SFE_NO_ERROR ; +- if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL) ++ if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != INVALID_HANDLE_VALUE) + { psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ; + return SFE_NO_ERROR ; + } ; +@@ -677,17 +677,15 @@ psf_open_rsrc (SF_PRIVATE *psf) + */ + snprintf (psf->rsrc.path.c, sizeof (psf->rsrc.path.c), "%s.AppleDouble/%s", psf->file.dir.c, psf->file.name.c) ; + psf->error = SFE_NO_ERROR ; +- if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != NULL) ++ if ((psf->rsrc.handle = psf_open_handle (&psf->rsrc)) != INVALID_HANDLE_VALUE) + { psf->rsrclength = psf_get_filelen_handle (psf->rsrc.handle) ; + return SFE_NO_ERROR ; + } ; + + /* No resource file found. */ +- if (psf->rsrc.handle == NULL) ++ if (psf->rsrc.handle == INVALID_HANDLE_VALUE) + psf_log_syserr (psf, GetLastError ()) ; + +- psf->rsrc.handle = NULL ; +- + return psf->error ; + } /* psf_open_rsrc */ + +@@ -738,9 +736,9 @@ psf_get_filelen (SF_PRIVATE *psf) + + /* USE_WINDOWS_API */ void + psf_init_files (SF_PRIVATE *psf) +-{ psf->file.handle = NULL ; +- psf->rsrc.handle = NULL ; +- psf->file.hsaved = NULL ; ++{ psf->file.handle = INVALID_HANDLE_VALUE ; ++ psf->rsrc.handle = INVALID_HANDLE_VALUE ; ++ psf->file.hsaved = INVALID_HANDLE_VALUE ; + } /* psf_init_files */ + + /* USE_WINDOWS_API */ void +@@ -798,9 +796,6 @@ psf_open_handle (PSF_FILE * pfile) + + handle = CreateFile2 (pfile->path.wc, dwDesiredAccess, dwShareMode, dwCreationDistribution, &cfParams) ; + +- if (handle == INVALID_HANDLE_VALUE) +- return NULL ; +- + return handle ; + #else + if (pfile->use_wchar) +@@ -824,9 +819,6 @@ psf_open_handle (PSF_FILE * pfile) + NULL /* handle to file with attributes to copy */ + ) ; + +- if (handle == INVALID_HANDLE_VALUE) +- return NULL ; +- + return handle ; + #endif + } /* psf_open_handle */ +@@ -860,14 +852,14 @@ psf_log_syserr (SF_PRIVATE *psf, int error) + /* USE_WINDOWS_API */ int + psf_close_rsrc (SF_PRIVATE *psf) + { psf_close_handle (psf->rsrc.handle) ; +- psf->rsrc.handle = NULL ; ++ psf->rsrc.handle = INVALID_HANDLE_VALUE ; + return 0 ; + } /* psf_close_rsrc */ + + + /* USE_WINDOWS_API */ int + psf_set_stdio (SF_PRIVATE *psf) +-{ HANDLE handle = NULL ; ++{ HANDLE handle = INVALID_HANDLE_VALUE ; + int error = 0 ; + + switch (psf->file.mode) +@@ -909,8 +901,7 @@ psf_set_file (SF_PRIVATE *psf, int fd) + + /* USE_WINDOWS_API */ int + psf_file_valid (SF_PRIVATE *psf) +-{ if (psf->file.handle == NULL) +- return SF_FALSE ; ++{ + if (psf->file.handle == INVALID_HANDLE_VALUE) + return SF_FALSE ; + return SF_TRUE ; +-- +2.27.0 + diff --git a/0005-Fix-NULL-file-handle-values.patch b/0005-Fix-NULL-file-handle-values.patch new file mode 100644 index 0000000000000000000000000000000000000000..a0b91c816eebbb7c095de88576cac8ce7af53805 --- /dev/null +++ b/0005-Fix-NULL-file-handle-values.patch @@ -0,0 +1,40 @@ +From 3101b92d50579d1ac7a3b06ad8e09a397938cdd3 Mon Sep 17 00:00:00 2001 +From: ctl-ly +Date: Thu, 29 Dec 2022 15:58:44 +0800 +Subject: [PATCH] Fix more NULL file handle values + +--- + src/file_io.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/file_io.c b/src/file_io.c +index 9901e86..046e027 100644 +--- a/src/file_io.c ++++ b/src/file_io.c +@@ -783,12 +783,12 @@ psf_open_handle (PSF_FILE * pfile) + break ; + + default : +- return NULL ; ++ return INVALID_HANDLE_VALUE ; + } ; + + #if defined (WINAPI_FAMILY_PARTITION) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) + if (!pfile->use_wchar) +- return NULL ; ++ return INVALID_HANDLE_VALUE ; + + CREATEFILE2_EXTENDED_PARAMETERS cfParams = { 0 } ; + cfParams.dwSize = sizeof (CREATEFILE2_EXTENDED_PARAMETERS) ; +@@ -1064,7 +1064,7 @@ psf_ftell (SF_PRIVATE *psf) + + /* USE_WINDOWS_API */ static int + psf_close_handle (HANDLE handle) +-{ if (handle == NULL) ++{ if (handle == INVALID_HANDLE_VALUE) + return 0 ; + + if (CloseHandle (handle) == 0) +-- +2.27.0 + diff --git a/libsndfile.spec b/libsndfile.spec index fb29a5dbe6339b058f4bb7bbf89e15d40e6f9c43..096a969f094623bb74c93ebc37559076ab6128df 100644 --- a/libsndfile.spec +++ b/libsndfile.spec @@ -1,6 +1,6 @@ Name: libsndfile Version: 1.0.31 -Release: 3 +Release: 4 Summary: Library for reading and writing sound files License: LGPLv2+ and GPLv2+ and BSD URL: http://libsndfile.github.io/libsndfile @@ -13,6 +13,8 @@ BuildRequires: sqlite-devel Patch1: 0001-CVE-2021-3246.patch Patch2: 0002-CVE-2021-4156.patch Patch3: 0003-Fix-memory-leak-in-caf_read_header.patch +Patch4: 0004-modify-error-value-for-Win32-file-handle.patch +Patch5: 0005-Fix-NULL-file-handle-values.patch %description Libsndfile is a C library for reading and writing files containing @@ -117,6 +119,11 @@ LD_LIBRARY_PATH=$PWD/src/.libs make check %{_mandir}/man1/sndfile-salvage.1* %changelog +* Thu Dec 29 2022 liying - 1.0.31-4 +- Use proper error value for Win32 file handle +- Fix more NULL file handle values +- Merge from https://github.com/libsndfile/libsndfile/pull/700 + * Thu Dec 29 2022 liying - 1.0.31-3 - Marked unimplemented dither enums in the header file as such. - Fix typo