Skip to content
Snippets Groups Projects
Commit d360da6b authored by Steve Lhomme's avatar Steve Lhomme
Browse files

contrib: medialibrary: import upstream patches

Fixing wstring usage with NULL strings.
parent 16e6c81d
No related branches found
No related tags found
1 merge request!5684contrib: medialibrary: import upstream patches
Pipeline #489016 failed with stages
in 28 minutes and 19 seconds
From af536d9421c471b386c1e2f308cc515679f8e26a Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 28 Jun 2024 07:59:28 +0200
Subject: [PATCH 2/7] win32: DeviceLister: don't use wchar_t string if they are
NULL
---
src/filesystem/win32/DeviceLister.cpp | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/filesystem/win32/DeviceLister.cpp b/src/filesystem/win32/DeviceLister.cpp
index 1f8c2a13..f784190c 100644
--- a/src/filesystem/win32/DeviceLister.cpp
+++ b/src/filesystem/win32/DeviceLister.cpp
@@ -74,8 +74,13 @@ std::vector<CommonDeviceLister::Device> DeviceLister::networkDevices() const
ss << "WNetEnumResource error: #" << GetLastError();
throw fs::errors::DeviceListing{ ss.str() };
}
- std::string mountpoint = charset::FromWide( netResources->lpLocalName ).get();
- std::string uuid = charset::FromWide( netResources->lpRemoteName ).get();
+ auto utf8_local = charset::FromWide( netResources->lpLocalName );
+ auto utf8_remote = charset::FromWide( netResources->lpRemoteName );
+ if ( !utf8_local || !utf8_remote )
+ continue;
+
+ std::string mountpoint = utf8_local.get();
+ std::string uuid = utf8_remote.get();
devs.emplace_back( std::move( uuid ),
std::vector<std::string>{ utils::file::toMrl( mountpoint ) }, true );
} while ( true );
@@ -118,7 +123,10 @@ std::vector<CommonDeviceLister::Device> DeviceLister::localDevices() const
if ( GetVolumePathNamesForVolumeName( volumeName, buffer, buffLength, &buffLength ) == 0 )
continue;
- std::string mountpoint = charset::FromWide( buffer ).get();
+ auto utf8_buffer = charset::FromWide( buffer );
+ if ( !utf8_buffer )
+ continue;
+ std::string mountpoint = utf8_buffer.get();
// Filter out anything which isn't a removable or fixed drive. We don't care about network
// drive here.
@@ -126,7 +134,10 @@ std::vector<CommonDeviceLister::Device> DeviceLister::localDevices() const
if ( type != DRIVE_REMOVABLE && type != DRIVE_FIXED && type != DRIVE_REMOTE )
continue;
- std::string uuid = charset::FromWide( volumeName ).get();
+ auto utf8_volume = charset::FromWide( volumeName );
+ if ( !utf8_volume )
+ continue;
+ std::string uuid = utf8_volume.get();
LOG_INFO( "Discovered device ", uuid, "; mounted on ", mountpoint, "; removable: ",
type == DRIVE_REMOVABLE ? "yes" : "no" );
--
2.45.0.windows.1
From 9245cc70cbae11d2a5d1d97c9e5f4a5a921119f3 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 28 Jun 2024 08:00:14 +0200
Subject: [PATCH 3/7] utils: Directory: don't use wchar_t string if they are
NULL
---
src/utils/Directory.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/utils/Directory.cpp b/src/utils/Directory.cpp
index a5c3684f..463b0c26 100644
--- a/src/utils/Directory.cpp
+++ b/src/utils/Directory.cpp
@@ -104,6 +104,11 @@ std::string toAbsolute( const std::string& path )
throw errors::System{ GetLastError(), "Failed to convert to absolute path" };
}
auto upath = charset::FromWide( buff );
+ if ( !upath )
+ {
+ LOG_ERROR( "Failed to convert ", path, " to UTF8" );
+ throw errors::System{ GetLastError(), "Failed to convert to UTF8" };
+ }
return file::toFolderPath( upath.get() );
#endif
}
@@ -209,6 +214,8 @@ bool rmdir( std::string path )
do
{
auto file = charset::FromWide( f.cFileName );
+ if ( !file )
+ continue;
if ( strcmp( file.get(), "." ) == 0 ||
strcmp( file.get(), ".." ) == 0 )
continue;
--
2.45.0.windows.1
From 19b3e069d3485f5bccc2712d9f96da1628800a22 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 28 Jun 2024 08:00:31 +0200
Subject: [PATCH 4/7] test: common: don't use wchar_t string if they are NULL
---
test/common/util.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/test/common/util.h b/test/common/util.h
index d0ff02ce..79d92fe0 100644
--- a/test/common/util.h
+++ b/test/common/util.h
@@ -36,6 +36,8 @@ static inline std::string getTempDir()
WCHAR path[MAX_PATH];
GetTempPathW( MAX_PATH, path );
auto utf8 = medialibrary::charset::FromWide( path );
+ if ( !utf8 )
+ return {};
return utf8.get();
#else
return "/tmp/";
--
2.45.0.windows.1
From fce5e4d3a7d9cc199dcc530b6f2d2dae0a544aa7 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 28 Jun 2024 08:17:23 +0200
Subject: [PATCH 5/7] LockFile: don't use char string if they are NULL
---
src/LockFile.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/LockFile.cpp b/src/LockFile.cpp
index acd65502..75f224dc 100644
--- a/src/LockFile.cpp
+++ b/src/LockFile.cpp
@@ -50,6 +50,9 @@ std::unique_ptr<LockFile> LockFile::lock( const std::string& mlFolderPath )
Handle handle;
#ifdef _WIN32
auto wide = charset::ToWide( lockFile.c_str() );
+ if ( !wide )
+ handle = INVALID_HANDLE_VALUE;
+ else
# if _WIN32_WINNT >= 0x0602 /* _WIN32_WINNT_WIN8 */
handle = CreateFile2(wide.get(), GENERIC_WRITE, 0, CREATE_ALWAYS, NULL);
# else
--
2.45.0.windows.1
From 154cccbef7e6be13f9f57d9eeef5eabfb5182a6a Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 28 Jun 2024 08:17:58 +0200
Subject: [PATCH 6/7] fs: Directory: don't use char string if they are NULL
---
src/filesystem/libvlc/Directory.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/filesystem/libvlc/Directory.cpp b/src/filesystem/libvlc/Directory.cpp
index 17594ab7..b08813c5 100644
--- a/src/filesystem/libvlc/Directory.cpp
+++ b/src/filesystem/libvlc/Directory.cpp
@@ -174,8 +174,10 @@ void Directory::addFile( std::string mrl, fs::IFile::LinkedFileType linkedType,
#ifdef _WIN32
/* We can't use _wstat here, see #323 */
+ auto wpath = charset::ToWide( path.c_str() );
WIN32_FILE_ATTRIBUTE_DATA attributes;
- if ( GetFileAttributesExW( charset::ToWide( path.c_str() ).get(),
+ if ( !wpath ||
+ GetFileAttributesExW( wpath.get(),
GetFileExInfoStandard, &attributes ) == 0 )
{
LOG_ERROR( "Failed to get ", path, " attributes" );
--
2.45.0.windows.1
From 71eb7e35818a03b0d0dc71ce45ea4ead406e5278 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Fri, 28 Jun 2024 08:23:47 +0200
Subject: [PATCH 7/7] utils: Directory: don't use char string if they are NULL
---
src/utils/Directory.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/utils/Directory.cpp b/src/utils/Directory.cpp
index 463b0c26..a0ff15ad 100644
--- a/src/utils/Directory.cpp
+++ b/src/utils/Directory.cpp
@@ -73,6 +73,8 @@ bool isDirectory( const std::string& path )
{
#ifdef _WIN32
auto wpath = charset::ToWide( path.c_str() );
+ if ( !wpath )
+ throw errors::System{ GetLastError(), ERR_FS_OBJECT_ACCESS + path };
auto attr = GetFileAttributes( wpath.get() );
if ( attr == INVALID_FILE_ATTRIBUTES )
throw errors::System{ GetLastError(), ERR_FS_OBJECT_ACCESS + path };
@@ -98,7 +100,7 @@ std::string toAbsolute( const std::string& path )
#else
wchar_t buff[MAX_PATH];
auto wpath = charset::ToWide( path.c_str() );
- if ( GetFullPathNameW( wpath.get(), MAX_PATH, buff, nullptr ) == 0 )
+ if ( !wpath || GetFullPathNameW( wpath.get(), MAX_PATH, buff, nullptr ) == 0 )
{
LOG_ERROR( "Failed to convert ", path, " to absolute path" );
throw errors::System{ GetLastError(), "Failed to convert to absolute path" };
@@ -136,7 +138,7 @@ bool mkdir( const std::string& path )
continue;
}
auto wFullPath = charset::ToWide( fullPath.c_str() );
- if ( _wmkdir( wFullPath.get() ) != 0 )
+ if ( !wFullPath || _wmkdir( wFullPath.get() ) != 0 )
#else
if ( ::mkdir( fullPath.c_str(), S_IRWXU ) != 0 )
#endif
@@ -203,6 +205,8 @@ bool rmdir( std::string path )
WIN32_FIND_DATA f;
auto pattern = path + '*';
auto wpattern = charset::ToWide( pattern.c_str() );
+ if ( !wpattern )
+ return false;
auto h = FindFirstFile( wpattern.get(), &f );
if ( h == INVALID_HANDLE_VALUE )
{
@@ -231,6 +235,8 @@ bool rmdir( std::string path )
}
} while ( FindNextFile( h, &f ) != 0 );
auto wPath = charset::ToWide( path.c_str() );
+ if ( !wPath )
+ return false;
auto res = _wrmdir( wPath.get() );
if ( res == 0 )
return true;
--
2.45.0.windows.1
......@@ -16,6 +16,12 @@ $(TARBALLS)/medialibrary-$(MEDIALIBRARY_VERSION).tar.bz2:
medialibrary: medialibrary-$(MEDIALIBRARY_VERSION).tar.bz2 .sum-medialibrary
$(UNPACK)
$(APPLY) $(SRC)/medialibrary/Fix-CacheWorker.patch
$(APPLY) $(SRC)/medialibrary/0002-win32-DeviceLister-don-t-use-wchar_t-string-if-they-.patch
$(APPLY) $(SRC)/medialibrary/0003-utils-Directory-don-t-use-wchar_t-string-if-they-are.patch
$(APPLY) $(SRC)/medialibrary/0004-test-common-don-t-use-wchar_t-string-if-they-are-NUL.patch
$(APPLY) $(SRC)/medialibrary/0005-LockFile-don-t-use-char-string-if-they-are-NULL.patch
$(APPLY) $(SRC)/medialibrary/0006-fs-Directory-don-t-use-char-string-if-they-are-NULL.patch
$(APPLY) $(SRC)/medialibrary/0007-utils-Directory-don-t-use-char-string-if-they-are-NU.patch
$(MOVE)
.medialibrary: medialibrary crossfile.meson
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment