From 96c003d2aa8a4ac3a11bdddf305af296395bafac Mon Sep 17 00:00:00 2001 From: ctl-ly Date: Thu, 29 Dec 2022 14:14:35 +0800 Subject: [PATCH 1/5] Use-proper-error-value-for-Win32-file-handle --- ...er-error-value-for-Win32-file-handle.patch | 147 ++++++++++++++++++ libsndfile.spec | 4 + 2 files changed, 151 insertions(+) create mode 100644 0004-Use-proper-error-value-for-Win32-file-handle.patch diff --git a/0004-Use-proper-error-value-for-Win32-file-handle.patch b/0004-Use-proper-error-value-for-Win32-file-handle.patch new file mode 100644 index 0000000..98a8767 --- /dev/null +++ b/0004-Use-proper-error-value-for-Win32-file-handle.patch @@ -0,0 +1,147 @@ +From b4887a3bf78c3d8c92bc2f4f52c6228e3fa7d344 Mon Sep 17 00:00:00 2001 +From: ctl-ly +Date: Thu, 29 Dec 2022 14:07:32 +0800 +Subject: [PATCH] fix + +--- + 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/libsndfile.spec b/libsndfile.spec index fb29a5d..a4f8843 100644 --- a/libsndfile.spec +++ b/libsndfile.spec @@ -13,6 +13,7 @@ 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-Use-proper-error-value-for-Win32-file-handle.patch %description Libsndfile is a C library for reading and writing files containing @@ -117,6 +118,9 @@ LD_LIBRARY_PATH=$PWD/src/.libs make check %{_mandir}/man1/sndfile-salvage.1* %changelog +* Thu Dec 29 2022 liying - 1.0.31-3 +- Use proper error value for Win32 file handle + * Thu Dec 29 2022 liying - 1.0.31-3 - Marked unimplemented dither enums in the header file as such. - Fix typo -- Gitee From 18e346511c62997df0bb8ab6b308ec77ab12cea5 Mon Sep 17 00:00:00 2001 From: ctl-ly Date: Thu, 29 Dec 2022 15:00:34 +0800 Subject: [PATCH 2/5] Use proper error value for Win32 file handle --- 0004-Use-proper-error-value-for-Win32-file-handle.patch | 6 +++--- libsndfile.spec | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/0004-Use-proper-error-value-for-Win32-file-handle.patch b/0004-Use-proper-error-value-for-Win32-file-handle.patch index 98a8767..8537252 100644 --- a/0004-Use-proper-error-value-for-Win32-file-handle.patch +++ b/0004-Use-proper-error-value-for-Win32-file-handle.patch @@ -1,7 +1,7 @@ -From b4887a3bf78c3d8c92bc2f4f52c6228e3fa7d344 Mon Sep 17 00:00:00 2001 +From 3f8343ccdc1c02ee4969eac9a056fd1999544522 Mon Sep 17 00:00:00 2001 From: ctl-ly -Date: Thu, 29 Dec 2022 14:07:32 +0800 -Subject: [PATCH] fix +Date: Thu, 29 Dec 2022 14:48:22 +0800 +Subject: [PATCH] Use proper error value for Win32 file handle --- src/file_io.c | 37 ++++++++++++++----------------------- diff --git a/libsndfile.spec b/libsndfile.spec index a4f8843..20920b5 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,7 +13,6 @@ 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-Use-proper-error-value-for-Win32-file-handle.patch %description Libsndfile is a C library for reading and writing files containing @@ -118,7 +117,7 @@ LD_LIBRARY_PATH=$PWD/src/.libs make check %{_mandir}/man1/sndfile-salvage.1* %changelog -* Thu Dec 29 2022 liying - 1.0.31-3 +* Thu Dec 29 2022 liying - 1.0.31-4 - Use proper error value for Win32 file handle * Thu Dec 29 2022 liying - 1.0.31-3 -- Gitee From b642c5dbd6d86ac1ce591c7c7ecc97d24a87d9df Mon Sep 17 00:00:00 2001 From: ctl-ly Date: Thu, 29 Dec 2022 15:51:25 +0800 Subject: [PATCH 3/5] add patch4 --- ....patch => 0004-modify-error-value-for-Win32-file-handle.patch | 1 + libsndfile.spec | 1 + 2 files changed, 2 insertions(+) rename 0004-Use-proper-error-value-for-Win32-file-handle.patch => 0004-modify-error-value-for-Win32-file-handle.patch (97%) diff --git a/0004-Use-proper-error-value-for-Win32-file-handle.patch b/0004-modify-error-value-for-Win32-file-handle.patch similarity index 97% rename from 0004-Use-proper-error-value-for-Win32-file-handle.patch rename to 0004-modify-error-value-for-Win32-file-handle.patch index 8537252..5ef0b43 100644 --- a/0004-Use-proper-error-value-for-Win32-file-handle.patch +++ b/0004-modify-error-value-for-Win32-file-handle.patch @@ -2,6 +2,7 @@ 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 ++++++++++++++----------------------- diff --git a/libsndfile.spec b/libsndfile.spec index 20920b5..1aa390b 100644 --- a/libsndfile.spec +++ b/libsndfile.spec @@ -13,6 +13,7 @@ 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 %description Libsndfile is a C library for reading and writing files containing -- Gitee From bd51108c484da0538a31d7e233de8cc545affcdd Mon Sep 17 00:00:00 2001 From: ctl-ly Date: Thu, 29 Dec 2022 16:01:02 +0800 Subject: [PATCH 4/5] Fix more NULL file handle values --- 0005-Fix-NULL-file-handle-values.patch | 40 ++++++++++++++++++++++++++ libsndfile.spec | 2 ++ 2 files changed, 42 insertions(+) create mode 100644 0005-Fix-NULL-file-handle-values.patch diff --git a/0005-Fix-NULL-file-handle-values.patch b/0005-Fix-NULL-file-handle-values.patch new file mode 100644 index 0000000..a0b91c8 --- /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 1aa390b..5afa335 100644 --- a/libsndfile.spec +++ b/libsndfile.spec @@ -14,6 +14,7 @@ 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 @@ -120,6 +121,7 @@ LD_LIBRARY_PATH=$PWD/src/.libs make check %changelog * Thu Dec 29 2022 liying - 1.0.31-4 - Use proper error value for Win32 file handle +- Fix more NULL file handle values * Thu Dec 29 2022 liying - 1.0.31-3 - Marked unimplemented dither enums in the header file as such. -- Gitee From e4bd7b3cf7862a1f562279410e6103885bbd4666 Mon Sep 17 00:00:00 2001 From: ctl-ly Date: Thu, 29 Dec 2022 16:29:22 +0800 Subject: [PATCH 5/5] Add upstream information --- libsndfile.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/libsndfile.spec b/libsndfile.spec index 5afa335..096a969 100644 --- a/libsndfile.spec +++ b/libsndfile.spec @@ -122,6 +122,7 @@ LD_LIBRARY_PATH=$PWD/src/.libs make check * 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. -- Gitee