[vlc-commits] [Git][videolan/vlc][3.0.x] 10 commits: modules: use WCHAR when calling wide char Win32 APIs

Steve Lhomme (@robUx4) gitlab at videolan.org
Sun Dec 1 15:24:56 UTC 2024



Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
abd424e6 by Steve Lhomme at 2024-12-01T14:57:47+00:00
modules: use WCHAR when calling wide char Win32 APIs

(cherry picked from commit 2f7271eaff83c6388ac0f629e44eb93b1e2da07e) (edited)
edited:
- removed freetype/fonts/win32.c and d3d11_fmt.c changes we were too different

- - - - -
669e44e9 by Steve Lhomme at 2024-12-01T14:57:47+00:00
ntservice: don't use a temporary conversion to printf a wide char string

(cherry picked from commit 987e7371bb8c4739c71a9d41c1f8839b1879867a)

- - - - -
b4f52122 by Steve Lhomme at 2024-12-01T14:57:47+00:00
win32: remove unused vlc_win32_tmpfile

(cherry picked from commit 7e2763d0882002827d4192fc499b1d6870bd05db) (rebased)
rebased:
- the code around is slightly different

- - - - -
51c25f6a by Steve Lhomme at 2024-12-01T14:57:47+00:00
es_out_timeshift: explicitely use GetTempPathW

The API is available in UWP builds. _wgetcwd() should work as well.

(cherry picked from commit d00ede66bf27211ca4a75975026f7f0ab312cab7) (edited)
edited:
- 3.0 already disabled the code in UWP differently

- - - - -
047b27e1 by Steve Lhomme at 2024-12-01T14:57:47+00:00
windrive: use ANSI API's to test drive letters

No need for wide chars for that. The API is supported in UWP [1].
The code was also puttin a WCHAR letter in a char string.

[1] https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdrivetypea

(cherry picked from commit ec8924b3a92c7a2c35ce930106140556d02c6038)

- - - - -
a89a24d0 by Steve Lhomme at 2024-12-01T14:57:47+00:00
ntservice: use ANSI API

All the internal strings we use are using CHAR.

(cherry picked from commit 4e84066f051be361306dae109aeb012efffe0f3b)

- - - - -
353a6526 by Steve Lhomme at 2024-12-01T14:57:47+00:00
eject: use ANSI API's to handle Windows drive letters

We don't need wide chars for this.

(cherry picked from commit 4d62dc124285f9e7488d100f3ebe2c841ce9d32d)

- - - - -
bfad5b4a by Steve Lhomme at 2024-12-01T14:57:47+00:00
win32: dirs: fix potential buffer overflow when appending "portable"

We let the concatenation decide if there's enough room or not.

And use the Wide char calls where wide char pointers are used.

(cherry picked from commit 28241fad50c5bca21ba13069f62f5d92f95f4805) (rebased)
rebased:
- the code around is slightly different

- - - - -
aef2b61f by Steve Lhomme at 2024-12-01T14:57:47+00:00
breakpad: remove MAX_PATH limits

It's unlikely the user path is that large, but just in case we are ready.

This fixes an issue where the result of _snwprintf() is not checked.
The wstringstream will only fail if there's no memory. At this point
further calls using std::map and breakpad will also fail.

(cherry picked from commit 05e7dae2fcd2b4b6483fc333b2f5257e84407e34)

- - - - -
aa197580 by Steve Lhomme at 2024-12-01T14:57:47+00:00
win32: dirs: avoid using wcscat_s

It seems it's not available in Windows XP.
https://forum.videolan.org/viewtopic.php?f=14&t=164742&p=544877#p544877

- - - - -


9 changed files:

- bin/breakpad.cpp
- include/vlc_fixups.h
- modules/control/ntservice.c
- modules/gui/eject.c
- modules/gui/skins2/win32/win32_factory.cpp
- modules/services_discovery/windrive.c
- src/input/es_out_timeshift.c
- src/win32/dirs.c
- src/win32/filesystem.c


Changes:

=====================================
bin/breakpad.cpp
=====================================
@@ -30,6 +30,7 @@
 #include <memory>
 #include <map>
 #include <string>
+#include <sstream>
 
 using google_breakpad::ExceptionHandler;
 
@@ -47,10 +48,10 @@ extern "C"
 
 void CheckCrashDump( const wchar_t* path )
 {
-    wchar_t pattern[MAX_PATH];
+    std::wstringstream pattern;
     WIN32_FIND_DATAW data;
-    _snwprintf( pattern, MAX_PATH, L"%s/*.dmp", path );
-    HANDLE h = FindFirstFileW( pattern, &data );
+    pattern << path << L"/*.dmp";
+    HANDLE h = FindFirstFileW( pattern.str().c_str(), &data );
     if (h == INVALID_HANDLE_VALUE)
         return;
     int answer = MessageBoxW( NULL, L"Ooops: VLC media player just crashed.\n" \
@@ -61,17 +62,17 @@ void CheckCrashDump( const wchar_t* path )
     params[L"ver"] = WIDEN(PACKAGE_VERSION);
     do
     {
-        wchar_t fullPath[MAX_PATH];
-        _snwprintf( fullPath, MAX_PATH, L"%s/%s", path, data.cFileName );
+        std::wstringstream fullPath;
+        fullPath << path << L'/' << data.cFileName;
         if( answer == IDYES )
         {
             std::map<std::wstring, std::wstring> files;
-            files[L"upload_file_minidump"] = fullPath;
+            files[L"upload_file_minidump"] = fullPath.str();
             google_breakpad::HTTPUpload::SendRequest(
                             WIDEN( BREAKPAD_URL "/reports" ), params, files,
                             NULL, NULL, NULL );
         }
-        DeleteFileW( fullPath );
+        DeleteFileW( fullPath.str().c_str() );
     } while ( FindNextFileW( h, &data ) );
     FindClose(h);
 }


=====================================
include/vlc_fixups.h
=====================================
@@ -657,10 +657,6 @@ void sincosf(float, float *, float *);
 char *realpath(const char * restrict pathname, char * restrict resolved_path);
 #endif
 
-#ifdef _WIN32
-FILE *vlc_win32_tmpfile(void);
-#endif
-
 /* mingw-w64 has a broken IN6_IS_ADDR_MULTICAST macro */
 #if defined(_WIN32) && defined(__MINGW64_VERSION_MAJOR)
 # define IN6_IS_ADDR_MULTICAST IN6_IS_ADDR_MULTICAST


=====================================
modules/control/ntservice.c
=====================================
@@ -140,9 +140,9 @@ void Close( vlc_object_t *p_this )
 static void *Run( void *data )
 {
     intf_thread_t *p_intf = data;
-    SERVICE_TABLE_ENTRY dispatchTable[] =
+    const SERVICE_TABLE_ENTRYA dispatchTable[] =
     {
-        { (WCHAR*) TEXT(VLCSERVICENAME), (LPSERVICE_MAIN_FUNCTION) &ServiceDispatch },
+        { (LPSTR)VLCSERVICENAME, (LPSERVICE_MAIN_FUNCTIONA) &ServiceDispatch },
         { NULL, NULL }
     };
 
@@ -165,7 +165,7 @@ static void *Run( void *data )
         return NULL;
     }
 
-    if( StartServiceCtrlDispatcher( dispatchTable ) == 0 )
+    if( StartServiceCtrlDispatcherA( dispatchTable ) == 0 )
     {
         msg_Err( p_intf, "StartServiceCtrlDispatcher failed" ); /* str review */
     }
@@ -185,7 +185,7 @@ static int NTServiceInstall( intf_thread_t *p_intf )
     intf_sys_t *p_sys  = p_intf->p_sys;
     char *psz_extra;
     struct vlc_memstream path_stream;
-    TCHAR psz_pathtmp[MAX_PATH];
+    WCHAR psz_pathtmp[MAX_PATH];
 
     SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
     if( handle == NULL )
@@ -204,14 +204,7 @@ static int NTServiceInstall( intf_thread_t *p_intf )
     /* Find out the filename of ourselves so we can install it to the
      * service control manager */
     GetModuleFileName( NULL, psz_pathtmp, MAX_PATH );
-    psz_extra = FromT( psz_pathtmp );
-    if ( !psz_extra )
-    {
-        CloseServiceHandle( handle );
-        return VLC_ENOMEM;
-    }
-    vlc_memstream_printf( &path_stream, "\"%s\" -I ntservice", psz_extra );
-    free(psz_extra);
+    vlc_memstream_printf( &path_stream, "\"%ls\" -I ntservice", psz_pathtmp );
 
     psz_extra = var_InheritString( p_intf, "ntservice-extraintf" );
     if( psz_extra && *psz_extra )


=====================================
modules/gui/eject.c
=====================================
@@ -124,14 +124,12 @@ static int intf_Eject( vlc_object_t *p_this, const char *psz_device )
     VLC_UNUSED(p_this);
 
 #if defined(_WIN32)
-    MCI_OPEN_PARMS op;
+    MCI_OPEN_PARMSA op = {};
     DWORD i_flags;
-    TCHAR psz_drive[4];
+    CHAR psz_drive[] = "X:";
 
-    memset( &op, 0, sizeof(MCI_OPEN_PARMS) );
-    op.lpstrDeviceType = (LPCTSTR)MCI_DEVTYPE_CD_AUDIO;
+    op.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_CD_AUDIO;
 
-    _tcscpy( psz_drive, TEXT("X:") );
     psz_drive[0] = psz_device[0];
     op.lpstrElementName = psz_drive;
 
@@ -139,7 +137,7 @@ static int intf_Eject( vlc_object_t *p_this, const char *psz_device )
     i_flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID |
               MCI_OPEN_ELEMENT | MCI_OPEN_SHAREABLE;
 
-    if( mciSendCommand( 0, MCI_OPEN, i_flags, (uintptr_t)&op ) )
+    if( mciSendCommandA( 0, MCI_OPEN, i_flags, (uintptr_t)&op ) )
         return VLC_EGENERIC;
 
     /* Eject disc */


=====================================
modules/gui/skins2/win32/win32_factory.cpp
=====================================
@@ -215,7 +215,7 @@ bool Win32Factory::init()
     m_trayIcon.uFlags = NIF_ICON|NIF_TIP|NIF_MESSAGE;
     m_trayIcon.uCallbackMessage = MY_WM_TRAYACTION;
     m_trayIcon.hIcon = LoadIcon( m_hInst, vlc_icon );
-    _tcscpy( m_trayIcon.szTip, vlc_name );
+    wcscpy( m_trayIcon.szTip, vlc_name );
 
     // Show the systray icon if needed
     if( var_InheritBool( getIntf(), "skins2-systray" ) )


=====================================
modules/services_discovery/windrive.c
=====================================
@@ -60,19 +60,19 @@ static int Open (vlc_object_t *obj)
 
     LONG drives = GetLogicalDrives ();
     char mrl[12] = "file:///A:/", name[3] = "A:";
-    TCHAR path[4] = TEXT("A:\\");
+    CHAR path[4] = "A:\\";
 
     for (char d = 0; d < 26; d++)
     {
         input_item_t *item;
-        char letter = 'A' + d;
+        CHAR letter = 'A' + d;
 
         /* Does this drive actually exist? */
         if (!(drives & (1 << d)))
             continue;
         /* Is it a disc drive? */
         path[0] = letter;
-        if (GetDriveType (path) != DRIVE_CDROM)
+        if (GetDriveTypeA (path) != DRIVE_CDROM)
             continue;
 
         mrl[8] = name[0] = letter;


=====================================
src/input/es_out_timeshift.c
=====================================
@@ -345,18 +345,18 @@ es_out_t *input_EsOutTimeshiftNew( input_thread_t *p_input, es_out_t *p_next_out
              (int)p_sys->i_tmp_size_max/(1024*1024) );
 
     p_sys->psz_tmp_path = var_InheritString( p_input, "input-timeshift-path" );
-#if defined (_WIN32) && !VLC_WINSTORE_APP
+#if defined (_WIN32)
     if( p_sys->psz_tmp_path == NULL )
     {
-        const DWORD count = GetTempPath( 0, NULL );
+        const DWORD count = GetTempPathW( 0, NULL );
         if( count > 0 )
         {
-            TCHAR *path = vlc_alloc( count + 1, sizeof(TCHAR) );
+            WCHAR *path = vlc_alloc( count + 1, sizeof(WCHAR) );
             if( path != NULL )
             {
-                DWORD ret = GetTempPath( count + 1, path );
+                DWORD ret = GetTempPathW( count + 1, path );
                 if( ret != 0 && ret <= count )
-                    p_sys->psz_tmp_path = FromT( path );
+                    p_sys->psz_tmp_path = FromWide( path );
                 free( path );
             }
         }


=====================================
src/win32/dirs.c
=====================================
@@ -226,17 +226,22 @@ static char *config_GetAppDir (void)
 {
 #if !VLC_WINSTORE_APP
     /* if portable directory exists, use it */
-    TCHAR path[MAX_PATH];
-    if (GetModuleFileName (NULL, path, MAX_PATH))
+    WCHAR path[MAX_PATH];
+    if (GetModuleFileNameW (NULL, path, MAX_PATH))
     {
-        TCHAR *lastDir = _tcsrchr (path, '\\');
+        WCHAR *lastDir = wcsrchr (path, L'\\');
         if (lastDir)
         {
-            _tcscpy (lastDir + 1, TEXT("portable"));
-            DWORD attrib = GetFileAttributes (path);
-            if (attrib != INVALID_FILE_ATTRIBUTES &&
-                    (attrib & FILE_ATTRIBUTE_DIRECTORY))
-                return FromT (path);
+            *lastDir = L'\0';
+            size_t pathlen = wcslen(path);
+            if ( pathlen + 1 + wcslen(L"\\portable" ) <= MAX_PATH )
+            {
+                wcscpy( &path[pathlen], L"\\portable" );
+                DWORD attrib = GetFileAttributesW (path);
+                if (attrib != INVALID_FILE_ATTRIBUTES &&
+                        (attrib & FILE_ATTRIBUTE_DIRECTORY))
+                    return FromWide (path);
+            }
         }
     }
 #endif


=====================================
src/win32/filesystem.c
=====================================
@@ -356,43 +356,3 @@ int vlc_accept (int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock)
         ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
     return fd;
 }
-
-#if !VLC_WINSTORE_APP
-FILE *vlc_win32_tmpfile(void)
-{
-    TCHAR tmp_path[MAX_PATH-14];
-    int i_ret = GetTempPath (MAX_PATH-14, tmp_path);
-    if (i_ret == 0)
-        return NULL;
-
-    TCHAR tmp_name[MAX_PATH];
-    i_ret = GetTempFileName(tmp_path, TEXT("VLC"), 0, tmp_name);
-    if (i_ret == 0)
-        return NULL;
-
-    HANDLE hFile = CreateFile(tmp_name,
-            GENERIC_READ | GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS,
-            FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL);
-    if (hFile == INVALID_HANDLE_VALUE)
-        return NULL;
-
-    int fd = _open_osfhandle((intptr_t)hFile, 0);
-    if (fd == -1) {
-        CloseHandle(hFile);
-        return NULL;
-    }
-
-    FILE *stream = _fdopen(fd, "w+b");
-    if (stream == NULL) {
-        _close(fd);
-        return NULL;
-    }
-    return stream;
-}
-#else
-FILE *vlc_win32_tmpfile(void)
-{
-    return NULL;
-}
-#endif
-



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4bf49f09cae811e00ec1e69252d476f44c8eb796...aa197580f26e74ed58cf38b17d871fc536940d1d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4bf49f09cae811e00ec1e69252d476f44c8eb796...aa197580f26e74ed58cf38b17d871fc536940d1d
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list