Skip to content

WinDirs...

Rika requested to merge runewalsh/source:windirs into main

Do two things.

  1. Simplify WinDirs (and fix certain nonfatal instances of wrong checks of function pointers).
  • 1.1. According to this comment and the issue it refers to, it loads shell32.dll the complicated way to prevent loading wrong shell32.dll accidentally or maliciously placed into the application directory. Honestly, the threat of spoofing wrong shell32.dll can be ignored just as the threat of spoofing wrong app.exe, but it doesn’t even exist in the first place because of a Windows feature named “Known DLLs”. See this StackOverflow answer and this ancient article.

  • 1.2. I don’t think error checking makes sense. System without shell32.dll etc. is corrupt past the point of being able to correctly run something that needs Windows special directories. Moreover, it already was non-existent: condition

if (@_SHGetFolderPathW = nil) and (@_SHGetKnownFolderPathW = nil) then
	raise Exception.Create('Could not locate '+SSHGetFolderPathW+' / '+SSHGetKnownFolderPathW+' functions');

is not met even if both function pointers are nils. (Exercise: explain why.) In a similar way, there’s no point in falling back to SHGetKnownFolderPath if SHGetFolderPath does not exist because it’s not like Microsoft likes removing functions. In a similar way, the code if CSIDLtoFOLDERID[I].FOLDERID <> nil then does not make sense at all.

  1. Delay-load ole32.dll (the unit was already delaying the loading of shell32.dll, though not for the performance but because it was concerned about not finding the functions). This makes the Windows version of the Free Pascal itself avoid loading ole32.dll unless actually required (namely, unless Windows special folders occur in paths, which usually does not happen). (Advertisement: think also of this MR.)

Merge request reports