Fix reading past the end of the string in Unix.FSearch.

This commit is contained in:
Rika Ichinose 2024-06-20 00:53:19 +03:00
parent ec21c75e05
commit c261d5fdee

View File

@ -1403,8 +1403,7 @@ Var
mydir,NewDir : RawByteString; mydir,NewDir : RawByteString;
p1 : cint; p1 : cint;
Info : Stat; Info : Stat;
i,j : cint; p,pe : PAnsiChar;
p : PAnsiChar;
Begin Begin
SetCodePage(dirlist,DefaultFileSystemCodePage); SetCodePage(dirlist,DefaultFileSystemCodePage);
if CurrentDirStrategy=CurrentDirectoryFirst Then if CurrentDirStrategy=CurrentDirectoryFirst Then
@ -1425,8 +1424,7 @@ Begin
Begin Begin
mypath:=ToSingleByteFileSystemEncodedFileName(path); mypath:=ToSingleByteFileSystemEncodedFileName(path);
p:=PAnsiChar(dirlist); p:=PAnsiChar(dirlist);
i:=length(dirlist); pe:=p+length(dirlist); { Points to terminating #0. }
j:=1;
Repeat Repeat
mydir:=RawByteString(p); mydir:=RawByteString(p);
if (length(mydir)>0) and (mydir[length(mydir)]<>'/') then if (length(mydir)>0) and (mydir[length(mydir)]<>'/') then
@ -1445,9 +1443,8 @@ Begin
End End
Else Else
NewDir:=''; NewDir:='';
while (j<=i) and (p^<>#0) do begin inc(j); inc(p); end; inc(p,IndexByte(p^,-1,0)+1); { Can increment to pe + 1 (at most). }
if p^=#0 then inc(p); Until (p>=pe) or (Length(NewDir) > 0);
Until (j>=i) or (Length(NewDir) > 0);
FSearch:=NewDir; FSearch:=NewDir;
SetCodePage(FSearch,DefaultRTLFileSystemCodePage); SetCodePage(FSearch,DefaultRTLFileSystemCodePage);
End; End;