[vlc-commits] [Git][videolan/vlc][master] win32: dirs: fix potential buffer overflow when appending "portable"

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Nov 28 08:55:55 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
28241fad by Steve Lhomme at 2024-11-28T08:42:48+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.

- - - - -


1 changed file:

- src/win32/dirs.c


Changes:

=====================================
src/win32/dirs.c
=====================================
@@ -120,16 +120,19 @@ static char *config_GetAppDir (void)
 {
     /* if portable directory exists, use it */
     WCHAR path[MAX_PATH];
-    if (GetModuleFileName (NULL, path, MAX_PATH))
+    if (GetModuleFileNameW (NULL, path, MAX_PATH))
     {
-        WCHAR *lastDir = wcsrchr (path, TEXT('\\'));
+        WCHAR *lastDir = wcsrchr (path, L'\\');
         if (lastDir)
         {
-            wcscpy (lastDir + 1, TEXT("portable"));
-            DWORD attrib = GetFileAttributes (path);
-            if (attrib != INVALID_FILE_ATTRIBUTES &&
-                    (attrib & FILE_ATTRIBUTE_DIRECTORY))
-                return FromWide (path);
+            *lastDir = L'\0';
+            if (wcscat_s(path, ARRAY_SIZE(path), TEXT("\\portable")) == 0)
+            {
+                DWORD attrib = GetFileAttributesW (path);
+                if (attrib != INVALID_FILE_ATTRIBUTES &&
+                        (attrib & FILE_ATTRIBUTE_DIRECTORY))
+                    return FromWide (path);
+            }
         }
     }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/28241fad50c5bca21ba13069f62f5d92f95f4805

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/28241fad50c5bca21ba13069f62f5d92f95f4805
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