Skip to content

Commit 071feb4

Browse files
author
Vadim Belov
committed
Initialize WIN32_FIND_DATA fields before calling GetPath
Fully initialize all fields of WIN32_FIND_DATAW.Data and set dwFileAttributes of WIN32_FIND_DATAA.Data to 0 before passing them to the respective GetPath methods. This prevents potential issues from uninitialized structure data.
1 parent 7c8c8b4 commit 071feb4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Sources/EasyExtensions.Windows/ShellLink.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,22 @@ public string Target
730730
if (linkA == null && linkW != null)
731731
{
732732
WIN32_FIND_DATAW fd = new WIN32_FIND_DATAW();
733+
fd.Data.ftCreationTime = new FILETIME();
734+
fd.Data.ftLastAccessTime = new FILETIME();
735+
fd.Data.ftLastWriteTime = new FILETIME();
736+
fd.Data.dwFileAttributes = 0;
737+
fd.Data.nFileSizeLow = 0;
738+
fd.Data.nFileSizeHigh = 0;
739+
fd.Data.dwReserved0 = 0;
740+
fd.Data.dwReserved1 = 0;
741+
fd.Data.cFileName = string.Empty;
742+
fd.Data.cAlternateFileName = string.Empty;
733743
linkW.GetPath(target, target.Capacity, ref fd, (uint)EShellLinkGP.SLGP_UNCPRIORITY);
734744
}
735745
else if (linkA != null && linkW == null)
736746
{
737747
WIN32_FIND_DATAA fd = new WIN32_FIND_DATAA();
748+
fd.Data.dwFileAttributes = 0;
738749
linkA.GetPath(target, target.Capacity, ref fd, (uint)EShellLinkGP.SLGP_UNCPRIORITY);
739750
}
740751
else

0 commit comments

Comments
 (0)