Răsfoiți Sursa

Strengthen CreateFileW's check.

Martijn Laan 10 luni în urmă
părinte
comite
aa1e83a139
1 a modificat fișierele cu 2 adăugiri și 1 ștergeri
  1. 2 1
      Projects/Src/Compression.SevenZipDecoder.pas

+ 2 - 1
Projects/Src/Compression.SevenZipDecoder.pas

@@ -75,7 +75,8 @@ function __CreateFileW(lpFileName: LPCWSTR; dwDesiredAccess, dwShareMode: DWORD;
 begin
 begin
   var ExpandedFileName: String;
   var ExpandedFileName: String;
   if PathExpand(lpFileName, ExpandedFileName) and
   if PathExpand(lpFileName, ExpandedFileName) and
-     ((PathCompare(ExpandedFileName, State.ExpandedArchiveFileName) = 0) or PathStartsWith(ExpandedFileName, State.ExpandedDestDir)) then
+     (((dwDesiredAccess = GENERIC_READ) and (PathCompare(ExpandedFileName, State.ExpandedArchiveFileName) = 0)) or
+      ((dwDesiredAccess = GENERIC_WRITE) and PathStartsWith(ExpandedFileName, State.ExpandedDestDir))) then
     Result := CreateFileW(PChar(ExpandedFileName), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)
     Result := CreateFileW(PChar(ExpandedFileName), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)
   else begin
   else begin
     Result := INVALID_HANDLE_VALUE;
     Result := INVALID_HANDLE_VALUE;